Multiple Instances Program Nodes

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:

public void generateScript(final ScriptWriter writer) {
writer.appendLine(getInstallation().getXMLRPCVariable() + “.LoadJob("” + model.get(“JobName”, “jobName.job”) + “")”);
}

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.

Is there something I’m missing about this?

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.

i came up to the same issue. is there a way to store objects rather than primitive data types with the model setter/getter methods?

1 Like

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?

Could you solved it? I’m having the same problem and I don’t know why the data is being shared, since it must not be.

@jbm I am seeing this problem again, I reproduced it with comments in the same way I explained earlier.

For some reason this bug does not happen if there is a space in the comment (might be other criteria as well)

Thanks, @ocohen
We fixed it, but seems it’s back and we are able to reproduce.
Thanks for reporting.