Hy everybody
I have a serious problem with a filtered beanitemcontainer grid.
This is how I tested: Vaadin 7.7.0 / SpringBoot v1.4.0 Application
-
user "
one
" load a filtered beanitemcontainer grid (PersonTable: id, name MySql-DB )
Filter assumption: “s” → All person with a “s” in the name -
user "
two
" load the same filtered beanitemcontainer grid but with another filter
Filter assumption: “e” → All person with a “e” in the name
We have now two user in the same Web-Application with different filtered beanitemcontainer person grids.
-
Now if user "
one
" select a row
→ java.lang.IllegalArgumentException: Given item id (16) does not exist in the container
at com.vaadin.ui.Grid$AbstractSelectionModel.checkItemIdExists(Grid.java:1373) ~[vaadin-server-7.7.0.jar:7.7.0]at com.vaadin.ui.Grid$SingleSelectionModel.select(Grid.java:1463) ~[vaadin-server-7.7.0.jar:7.7.0]
at com.vaadin.ui.Grid$SingleSelectionModel$1.select(Grid.java:1448) ~[vaadin-server-7.7.0.jar:7.7.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_72]
This is really strange, it seems the beanItemContainer is the same for both user?
Code snippets:
private TextField filterText = new TextField();
private HashMap<Object, Object> sqlFilter = new HashMap<Object, Object>();
public BeanItemContainer<Person> beanItemContainer = new BeanItemContainer<>(Person.class)
// Filter and load
filterText.addTextChangeListener(e -> {
sqlFilter.put("name", e.getText());
grid.setContainerDataSource(getPersonList(sqlFilter));
});
@Override
public BeanItemContainer<Person> getPersonList(HashMap<Object, Object> sqlFilter) {
personBeanItemContainer.removeAllItems();
personBeanItemContainer.addAll(personDAO.list(sqlFilter)); //Get all filtered Person; Table person fields id, name MySQL-DB
return personBeanItemContainer;
}
grid.setSelectionMode(SelectionMode.SINGLE);
grid.setContainerDataSource(getPersonList(sqlFilter));
grid.addSelectionListener(event -> {
BeanItem<Person> item = (BeanItem<Person>) grid.getContainerDataSource().getItem(grid.getSelectedRow());
});