Reputation: 114
I have a situation where the user is prompted with a twin column selector. The options column is populated based on a selection of a combo box.
So, I need "options list" to change based on combo box selection. But I want the selected values to remain the same.
eg. combo box value = international
options column is populated international with users.
combo box value = local
options column is populated with local users.
At the end, when I collecting the selected values, it may contain both local and international users.
Something like this:
twinColSelect.removeAllFromLeft();
twinColSelect.addItemsToLeft(internationlUsersList);
How do I achieve this? I tried the following approach; somehow I can get the selected values from the code. But from the frontend I can only see is selected values from the current options list.
myComboBox.addValueChangeListener(event1 -> {
Object value = twinColSelect.getValue();
twinColSelect.removeAllItems();
myComboBox.getValue.getUsers().forEach(ob -> twinColSelect.addItem(ob.getUserName()));
twinColSelect.setValue(value);
});
Upvotes: 0
Views: 1128
Reputation: 114
I found a workaround. It's not perfect, but it gets the job done.
This is what I did, before removing all items, I saved the selected values. Then remove all items. After that, I added my 'new values' and previously saved 'selected values' to the item list.
Then it was possible to set selected values to the list
Object selectedValues=twinSelect.getValue();
twinSelect.removeAllItems();
twinSelect.addItems(newITemsList);
(Collection<?>selectedValues.forEach(o ->twinSelect.addItem(o));
twinSelect.setValue(selectedValues);
Upvotes: 0