Vaadin TwinColSelect 从选项列中删除项目而不删除选定的列值

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

是这样的,我有一个情况,提示用户使用双列选择器。选项列根据组合框的选择进行填充。

因此,我需要 "options list" 根据组合框选择进行更改。但我希望所选值保持不变。

eg. combo box value = international
options column is populated international with users. 

combo box value = local
options column is populated with local users.

最后,当我收集选择的值时,它可能包含本地和国际用户。

像这样。

twinColSelect.removeAllFromLeft();
twinColSelect.addItemsToLeft(internationlUsersList);

如何存档?我尝试了以下方法;我可以以某种方式从代码中获取选定的值。但是从前端我只能看到当前选项列表中的选定值。

myComboBox.addValueChangeListener(event1 -> {

    Object value = twinColSelect.getValue();
    twinColSelect.removeAllItems();
    myComboBox.getValue.getUsers().forEach(ob -> twinColSelect.addItem(ob.getUserName()));
    twinColSelect.setValue(value);
});

如果我的问题不清楚,请发表评论。 先谢谢了。 :)

我找到了解决方法。它并不完美,但它完成了工作。

这就是我所做的,在删除所有项目之前,我保存了选定的值。 然后删除所有项目。之后,我将我的 'new values' 和之前保存的 'selected values' 添加到项目列表中。

然后可以将选定的值设置到列表中

Object selectedValues=twinSelect.getValue();

twinSelect.removeAllItems();

twinSelect.addItems(newITemsList);

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

twinSelect.setValue(selectedValues);