Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
How to filter a TwinColSelect?
Found a way:
1. Create a BeanItemContainer and set in the TwinColSelect, called the field 'container'.
2. Add the Items to the container.
3. Configure the TwinColSelect:
- .setItemCaptionPropertyId("your field on the item");
- .setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY);
4. When filtering:
- container.removeAllContainerFilters();
- container.addContainerFilter( myTwinColSelect.getItemCaptionPropertyId(), "the filter", true, false);
It works.
s b: Can you please share some code for this
I am trying the following and dont seem to be working. would appreciate if anyone can respond with a solution
public class Vaadinprj2Application extends Application {
private static final long serialVersionUID = 1L;
private TwinColSelect selection;
private TextField filter;
private VerticalLayout ver;
@Override
public void init() {
final Window main = new Window();
filter = new TextField();
selection = new TwinColSelect("TWINCOL NAME");
ver = new VerticalLayout();
selection.setColumns(8);
filter.setColumns(7);
filter.setImmediate(true);
selection.setImmediate(true);
setMainWindow(main);
List<String> mystrslist = new ArrayList<String>();
mystrslist.add("HARPAL");
mystrslist.add("MUSTAN");
mystrslist.add("SHANMUKHA");
mystrslist.add("HARI");
mystrslist.add("RAVI");
mystrslist.add("RAGHU");
mystrslist.add("KHUN");
mystrslist.add("CHARAN");
mystrslist.add("SAMEER");
mystrslist.add("AMAR");
mystrslist.add("ANANT");
final BeanItemContainer<String> beans = new BeanItemContainer<String>(
String.class);
beans.addAll(mystrslist);
selection.setContainerDataSource(beans);
selection.setItemCaptionMode(TwinColSelect.ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID);
filter.setTextChangeEventMode(TextChangeEventMode.LAZY);
filter.addListener(new TextChangeListener() {
/**
* addContain
*/
private static final long serialVersionUID = 1L;
public void textChange(TextChangeEvent event) {
// beans.removeAllContainerFilters();
System.out.println("THE VALUE IS " + event.getText() + " ID: "
+ selection.getItemIds().toString());
beans.addContainerFilter(selection.getItemCaptionPropertyId(),
event.getText(), true, false);
}
});
ver.addComponent(selection);
ver.addComponent(filter);
main.addComponent(ver);
}
}
You listener does not work, this one does :
filter.addTextChangeListener(new TextChangeListener() {
/**
* addContain
*/
private static final long serialVersionUID = 1L;
public void textChange(final TextChangeEvent event) {
beans.removeAllContainerFilters();
beans.addContainerFilter(new Filter() {
@Override
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
if (((String) itemId).toLowerCase().contains(event.getText().toLowerCase())
|| ((Collection) selection.getValue()).contains(itemId))
return true;
else
return false;
}
@Override
public boolean appliesToProperty(Object propertyId) {
return true;
}
});
}
});
Hope that help !