udakarajd udakarajd - 1 year ago 338
Java Question

Vaadin TwinColSelect remove items from option column without removing selected column values

This is the case, I have a situation where the user is prompt 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 collect the selected values, it may contain both local and international users.

something like this.


How do I archive 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();
myComboBox.getValue.getUsers().forEach(ob -> twinColSelect.addItem(ob.getUserName()));

If my question is not clear, please leave a comment.
Thanks in advanced. :)

Answer Source

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();



(Collection<?>selectedValues.forEach(o ->twinSelect.addItem(o));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download