How to catch an exception when filtering a vaadin mesh

Using vaadin (7.7.3) I filter the grid by name, this filtering takes a couple of seconds to remove objects from the Grid gui. So, if I click on this timeline on the Grid line that is removed from the Container , it throws an exception:

 Caused by: java.lang.IllegalArgumentException: Given item id (5422bef6-e472-4d3e-af54-316c52d373da) does not exist in the container at com.vaadin.ui.Grid$AbstractSelectionModel.checkItemIdExists(Grid.java:1371) at com.vaadin.ui.Grid$SingleSelectionModel.select(Grid.java:1460) at com.vaadin.ui.Grid$SingleSelectionModel$1.select(Grid.java:1445) 

I think this is normal because it removes objects from the Container and then it will propagate to gui.

I thought of checkItemIdExists() exception by overwriting the checkItemIdExists() method in my Grid class, but it would catch an exception for every situation, and that is not the behavior I'm looking for.

My question is: how can I fix this exception in this particular case?

+6
source share
2 answers

The only workaround I found was to override the mesh selection model in Vaadin to disable the checkItemIdExists method. This is the method that throws the exception that you have.

 import com.vaadin.ui.Grid.SelectionModel; import com.vaadin.ui.Grid.SingleSelectionModel; public class SingleSelectionModelNotChecked extends SingleSelectionModel implements SelectionModel { @Override protected void checkItemIdExists(Object itemId) throws IllegalArgumentException { // Nothing to do. No check is done, no exception is launched when the filter is applying. } } 

Now you can include this in your group:

 setSelectionModel(new SingleSelectionModelNotChecked()); 

Of course, now the grid cannot verify that the element selected in the grid or not.

+1
source

You can use Viritin add-ons https://vaadin.com/directory#!addon/viritin it supports server-side swapping, Vaadin Grid will load all the data from the database or you will use your data source to send a ContainerDataSource.

0
source

Source: https://habr.com/ru/post/1011467/


All Articles