# After deleting and re-deploying the same URCap, the components are having the same values

**URL:** <https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088>\
**Category:** URCap Development\
**Created:** [October 9, 2020, 12:46pm UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088 "2020-10-09T12:46:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon5706138](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon5706138](https://forum.universal-robots.com/u/anon5706138)\
**Post date:** [October 9, 2020, 12:46pm UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088/1 "2020-10-09T12:46:28Z")

</div>

Hello,

I have a URCap which has multiple ComboBoxes. The ComboBoxes are defined as private.

I add a few objects to the ComboBoxes when pushed a button.

But after removing the URCap from TreeNode and re-deploying them, the ComboBoxes have the objects I have added before deleting.

The values of the components I altered stayed with the URCap after removing them. Or when I add another one of the same URCap, the values stay the same.

I don’t know if I was able to explain the issue but the values of the components stay the same for different instances of the same URCap.

How can I reset them?

Thank you,

MB

---

<div class="post-metadata">

**Author:** ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)\
**Post date:** [October 9, 2020, 1:00pm UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088/2 "2020-10-09T13:00:14Z")

</div>

Where are the combo boxes you are referring to? Are they in program nodes or in the installation node? If you are loading the same saved program before and aftrer reinstallation of the URCap, then you should expect the program to remember the values in the combo box, assuming you use a program nodes `DataModel` to repopulate the combo boxes… Likewise if you have saved an installation file, if you remove the URCap and reinstall, the installation file will keep the data from the uninstalled URCap saved so that it can be re applied upon reinstallation, and again if these combo boxes are populated using data you save to the installation’s `DataModel`, this is the expected behaviour.

The other possibility assumes that your problem is with the UI not changing when clicking between different instances of different program noes of the same type. This is because whilst each program node has its own `DataModel` that is unique to a given program node instance, there is only a single instance of the view class that is used by each instance of that program node. This means that in order to update the UI for each program node, you should save information to a program nodes `DataModel` and then in `openView(), use the information saved in the data model to change any required UI components,

We would need more inforamtion about the circumstances under which this is happening in order to help confirm the cause of the problem you are seeing, hopefully 1 of the 2 above solutions above helps.

---

<div class="post-metadata">

**Author:** ![anon5706138](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon5706138](https://forum.universal-robots.com/u/anon5706138)\
**Post date:** [October 9, 2020, 2:16pm UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088/3 "2020-10-09T14:16:54Z")

</div>

I have declared the combo boxes in the ProgramNodeView. I didn’t use DataModel to populate the ComboBoxes.

```
private String[] forCombo = {"1", "2", "3"};

private JComboBox<String> comboBox = new JComboBox<String>(forCombo);

private String[] forCombo1 = {"first", "1", "2", "last"};

private JComboBox<String> comboBox1 = new JComboBox<String>(forCombo1);

```

As far as I know, DataModel can’t be used in ProgramNodeView. When I tried to add it like this in the ProgramNodeService:

@Override  
public dWellView createView(ViewAPIProvider apiProvider, DataModel model) {  
// TODO Auto-generated method stub  
return new dWellView(apiProvider, model);  
}

An error occured.

> [@sam.verity-hilton](#):
>
> This means that in order to update the UI for each program node, you should save information to a program nodes `DataModel` and then in `openView(), use the information saved in the data model to change any required UI components

I believe what you stated above is the only solution but how to do that?

I don’t have any installation nodes in my program.

---

<div class="post-metadata">

**Author:** ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)\
**Post date:** [October 12, 2020, 7:58am UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088/4 "2020-10-12T07:58:17Z")

</div>

The error occurs since as I stated, there is only ever 1 instance of the `programNodeView`, and so the view can be given a specific instance of a `DataModel`. Think of the view class as “static”, for want of a better word.

You will need to fetch the specific contribution instance in the view class in order to save to the currently active `DataModel`. This will be performed in a listener of some sort which I assume you already have implemented (if not have a look at [this post](https://stackoverflow.com/questions/58939/jcombobox-selection-change-listener)) to perform actions when changes to the comboBox occur. You need to use the `ContributionProvider` that is passed to the view class in `buildUI()`. The contribution provider has a pethod called `get()` which returns the current contribution instance. From there, make a public method in your contribution class that passed and can save any necessayry data to the data model.

---

<div class="post-metadata">

**Author:** ![anon5706138](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon5706138](https://forum.universal-robots.com/u/anon5706138)\
**Post date:** [October 13, 2020, 10:04am UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088/5 "2020-10-13T10:04:25Z")

</div>

Hello,

I have created 2 arrays of String in ProgramNodeView.

Then I have created a function in ProgramNodeContribution:

```
private static final String COMBO = "comboBox";

private static final String COMBO1 = "comboBox1";

private static final String[] DEF_COMBO = {"default_value"}; 

public void setComboBoxesC(final String[] combo1, final String[] combo) {

    undoRedoManager.recordChanges(new UndoableChanges() {
        
        @Override
        public void executeChanges() {

            model.set(COMBO1, combo1);
            model.set(COMBO, combo);
        }
    });
    
    
    view.setComboBoxes(model.get(COMBO1, DEF_COMBO), model.get(COMBO, DEF_COMBO));
}

```

There is another function called setComboBoxes in ProgramNodeView that sets the String arrays to the comboBoxes:

I believe I used the DataModel as you have instructed but the same issue still persists. When I add another instance of this same Node the comboBoxes have values which were set in the instance before this.

Am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)\
**Post date:** [October 13, 2020, 10:56am UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088/6 "2020-10-13T10:56:49Z")

</div>

You will need to call `view.setComboBoxes()` in `openView()` of your contribution class to update them when adding/flicking between nodes. The UI objects stored in the view class will only ever change when they are told to do so (usually by the contribution) so you have to make sure to change them in `openView()` as well as in your listeners.

---

<div class="post-metadata">

**Author:** ![anon5706138](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon5706138](https://forum.universal-robots.com/u/anon5706138)\
**Post date:** [October 13, 2020, 12:08pm UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088/7 "2020-10-13T12:08:59Z")

</div>

I called the view.setComboBoxes() in openView() from ProgramNodeContribution as was told.

```
public String[] getModel1() {
    return model.get(COMBO1, DEF_COMBO1);
}

public String[] getModel() {
    return model.get(COMBO, DEF_COMBO);
}

@Override
public void openView() {
    view.setComboBoxes(getModel1(), getModel());
}

```

The function in ProgramNodeView which was called from ProgramNodeContribution is below.

```
public void setComboBoxes(String[] Combo1, String[] Combo) {
    
    comboBox1.setModel(new DefaultComboBoxModel<String>(Combo1));
    
    comboBox.setModel(new DefaultComboBoxModel<String>(Combo));
    
}

```

The same issue still persists. The items of Combo Boxes in a Node exist in another instance as well.

Also, the items in ComboBoxes are not updated automatically. They are updated after clicking another Node and clicking back to our Node which has ComboBoxes.

---

<div class="post-metadata">

**Author:** ![anon5706138](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon5706138](https://forum.universal-robots.com/u/anon5706138)\
**Post date:** [October 13, 2020, 2:34pm UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088/8 "2020-10-13T14:34:19Z")

</div>

Hello,

I found the problem. It was told that global variables should not be stored to the DataModels.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/f/f5d95b1e1465be3bd7ad1e820b5541abd12ccb0e.png)

That was exactly what I was trying to do.

Instead of using global variable, I have used it an instance variable. There is no problem right now except for not auto-updating the items in comboBoxes.

Thank you for your time Sam

---

<div class="post-metadata">

**Author:** ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)\
**Post date:** [October 14, 2020, 7:58am UTC](https://forum.universal-robots.com/t/after-deleting-and-re-deploying-the-same-urcap-the-components-are-having-the-same-values/9088/9 "2020-10-14T07:58:03Z")

</div>

Happy to help 🙂
