How to set content of text control in screencode - text

I just can't believe how hard this is.
I would like to edit the content of a Control with Type text. I'm working with lightswitch visual studio 2012. I would like to change this in the screencode (so programmatic).
I gave the control the name: "Message".
Right now, I'm trying this.FindControl("Message")., but there doesn't seem to be any property I can call to set the content. Nether can I cast the control to the correct Type text. Even Text doesn't seem to be a valid className.
Any Help on how to set the content of this control?
EDIT: Should I shoot the ControlAvailable event and try to modify content there?

You're on the right track with this.FindControl("Message"). The way to set a property on it once you have found it is as follows:
this.FindControl("Message").SetProperty("propertyToSet", [new value])

Actually, trying to set the value of a control on a screen is the wrong way to do it.
In LightSwitch, every control is bound to a property (usually an entity's property, but might also be a screen property), so setting the value of that property will update the control.
So if you have a detail screen that is bound to an entity (let's call it ClientProperty), & you have a TextBox control (let's call it MessageControl) bound to ClientProperty's Message property, all your code needs to do to change the value is:
Me.ClientProperty.Message = "This is a message"
If instead, you had a TextBox control (again, let's call it MessageControl) that's bound to a screen property (called Message), your code is as simple as:
Me.Message = "This is another message"
It seems "hard" the way you're trying to do it because it's not meant to be done that way.

Related

Xpages - Custom control getting a custom property from another custom control

I've searched google and stack but can't seem to find a definitive answer. What I would like to do, is something like this:
Say I have custom control A, within which, is a radio button, when I click it, I want it to grab a custom property that is set on custom control B, lets say compositeData.Name as an example. Can I do this?
If I give custom control B an ID, lets say ccB, can the radio button in custom control A do something like, getComponent("ccB").getValue().compositeData.Name so I can get the value of the property I passed into custom control B using the custom property 'Name'?
If its a straight no, at least I know to stop playing around with the idea! Thanks
Reaching from one control into the inside of another control would break component isolation. You might want to take a different approach:
Option a - client side:
Your control emits a JavaScript event that bubbles up until it reaches a parent element that contains the control you want to change (presumably the parent Dom element). There you set the property of that element.
Option b - server side:
As Urs suggested: bind both to a bean and handle the updates inside the bean

EditBox fieldInput.getValue() and spaces

Here is the issue. I have an editBox which I am trying to retrieve the value from by server side JavaScript via the onClick event of a button named Add. It works until space is in the value, then it retrieves nothing. Code for the onClick events is as follows:
println("Button Clicked");
try{
var forkNumberInput:com.ibm.xsp.component.xp.XspInputText =
getComponent("forkNumberInput");
var forkNum = forkNumberInput.getValue();
viewScope.ForkNum = forkNum;
println(forkNum);
} catch(e){
println( Error in Add button: " + e.toString());
}
When a space is in the text the viewScope doesn't get populated and nothing is written to the server log not even "Button Clicked". No error is written to server log.
If "Button Clicked" is not printed, the likeliest cause is that there are validation errors. Add a Display Errors control to make sure that's not the case.
I second Paul's suggestion to add the Errors control. Besides that: Try to avoid to use getComponent() when all you want to do is grabbing the value. The idea of JSF, extending to XPages, is "data binding". Controls are bound to some data source for their value and you interact with those. getComponent() is meant to be used when you need to manipulate anything else.
So you would go and bind your control that scope variable viewScope.forkNum and you are done. Your button then grabs the value from there and does what it needs to do.
So in summary: Controls want to be bound. Data lives in models (not controls)
Thanks Paul - you led me to the right direction. It turned out that there was a validateConstraint under Properties > data > validators. I removed the validateConstraint and it started working. That's what happens when you copy design elements from one custom control to another.

How to interact with control properties after a call to a managed action?

I have a managed action with returns bool when a button is pressed.
Depending on if true / false is returned I want to be able to change the properties of controls on the dialog. Not limited to just the text value.
Is this possible, for example the visibility, etc?
It is possible, however you will have to make sure there is a set-property control event (after your managed code custom action do-event) that touches a property related to anything you want the UI to update. If you change a property value within the managed code, or via the wrapper InstallShield provides, the Windows Installer UI doesn't track the change and update in response.
So, for example, you could wire your return value to the property RETURNVALUE, and then add a control event that sets better named properties like MYCONTROLTEXT or SHOWMYCONTROL; the control or its conditions would be wired to those better named properties.

Why is my fileDownload control showing the trashcan even in read mode?

This is a rather strange one I think, and I'm sure I made a mistake here myself:
in one of my applications I'm showing a fileDownload control bound to a Richtext field in my underlying NotesDocument. The control's properties a are set to Hide if no attachments, show size, type and created as well as allow delete. The control itself sits inside a custom control, being part of another custom control, similar to this:
Xpage.xsp
- ccContainer
- - ccInnerDoc
Document datasources for both the container and the "inner" doc are defined at the root of ccContainer and passed into the inner doc.
The inner doc's datasource is comnputed based on a document selection, and it's igenoreRequestParams property is set to false so that I can display the contents of the selected datasource in a given panel etc.
The selected doc is first opened in read mode, and I can set it to edit mode using a button.
Problem now is that my file download control always is showing the delete icon (trashcan) no matter which mode the doc is opened in. And it's not only the icon showing, it also pretends to work by asking me whether I really want to delete and then really removes the file attachment. Only that this change of course cannot be stored into the datasource because it's only open in read mode.
I'm sure that this behaviour is some side-effect of something else in my application (to a certain extent I rebuilt this in a plain new db and until now cannot reproduce it), but I'm at the end of my knowledge of what this could be.
Any hint of what could be causing this is more than welcome.
In place of #Frantisek Kossuth I answer this myself: see compute dynamically the allowDelete property of file download xpages
Thanks again, Frantisek!

What's the purpose of the GtkWidget.events property for (like) GtkTreeView widgets?

I have a Glade GUI description file with a GtkTreeView in a GtkHBox in a window; and there's a handler for the row_activated signal. Now, Glade has automatically set the "events" property (inherited from GtkWidget) of that treeview to some value (GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK). And there are two strange things with this:
removing the pre-set value (so that the property is empty) doesn't seem to break the application (at least not with the old GTK 2.10 I have atm).
in fact, an annoying bug I has seen before (where the treeview items would not correctly react to expand or collapse clicks) is now gone!
I have yet to test this with a newer GTK version, but the question is already there: exactly what is the purpose for this events property? And why does Glade automatically and unnecessarily set it to some value? Does this have some side effects I'm not aware of?
It's a bug in glade, it always sets the event property of widgets it create. It has no notion of the default value of a property so it always sets it.
Doesn't this mask indicate the events you're willing to receive? In this case, you'll probably want to receive notification that the user has clicked or double-clicked an item in the GtkTreeView, and you'll want to register callbacks to handle these events.
me.yahoo.com/a/kUQ7zeQ: but even if I set the property to an empty string as mentioned, the row_activated handler is still called when I double-click on a row (or press Enter or Space). So the treeview still gets events...

Resources