I am currently writing my first URCap, so I might not completley understand how this works.
I have a program node which accepts a single text input and act accordingly:
public void openView() {
lblJobName.setText(“Enter Job File Name (inc. extension):”);
txtJobName.setText(model.get(“JobName”, “jobName.job”));
}
public void closeView() {
model.set(“JobName”, txtJobName.getText());
}
public boolean isDefined() {
return !txtJobName.getText().equals(“”);
}
public void generateScript(final ScriptWriter writer) {
writer.appendLine(getInstallation().getXMLRPCVariable() + “.LoadJob("” + txtJobName.getText() + “")”);
}
If I only have one instance of this program node, everything works fine. But if I have two instances - things get weird. Even though the text in the text boxes is different, both nodes write the same line out.
At first I thought they might be sharing the model object, so i changed generateScript to:
and now it seems to work fine. Except that if one of the nodes becomes undefined (by setting the txt box to “”) both show up as yellow in the program tree.
You should use the DataModel object to store your values.
There is only 1 instance of the UI, so if you have multiple program nodes, you will experience a “ghosting” between the nodes - since what was entered in a previous node, will also be shown in the UI when navigating to the next one.
So you should implement a callback for the UI interaction to read the value of e.g. a textfield, and store this in the DataModel. And use the DataModel to retrieve the value when generating script or loading the UI on openView.
This is also the method demonstrated in the HelloWorld URCap for generating the HelloWorld popup.
Thanks Jacob for your reply,
The “ghosting” creates a weird bug: Say i have 2 “Comment” nodes, I view the first one and enter some text to the text field. I need to press “submit” on the keyboard for this text to be saved.
If instead of pressing submit I switch to the second Comment node, the text will be saved in the 2nd one.
Do you know about this issue? It’s not a critical bug, but is kind of confusing.
(of course the same thing happens if I have 2 instances of the same URCap node)
@ocohen
I am not able to re-produce the behavior of the Comment nodes.
When I switch views to another Comment-command, the text is automatically submitted to the original node in focus.
What software version did you experience this on?