6

Using vaadin (7.7.3) I'm filtering a grid by name, this filtering takes a couple seconds to remove the objects from the Grid gui. And so, if I click on that timelapse a row of the Grid which is removed from the Container, it raises 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 guess this is normal because it removes the objects from the Container and then it will propagate to the gui.

I have thought of catching the exception overwriting the checkItemIdExists() method in my Grid class but it would catch the exception for every situation and that is not the behavior I am looking for.

My question is: How can I capture this exception just in this case?

Alex
  • 325
  • 1
  • 2
  • 8
  • Are you asking how to unselect the element before using the filter? or are you asking how to avoid this exception? – King Midas Oct 27 '16 at 11:46
  • Simply catch IllegalArgumentException.. – Jobin Oct 31 '16 at 06:39
  • Catching the exception is not possible. This exception is not launched in the application code. Seems that is launched by the vaadin component library when using the component. – King Midas Oct 31 '16 at 08:40

2 Answers2

1

The only workaround I have found, is to override the selection model of the grid in Vaadin to disable the checkItemIdExists method. This is the method that launches the exception 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. 
    }
}

You can now include this into your gird with:

setSelectionModel(new SingleSelectionModelNotChecked());

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

King Midas
  • 1,442
  • 4
  • 29
  • 50
0

You can use Viritin Add-on https://vaadin.com/directory#!addon/viritin it supports server side paging, Vaadin Grid will load all data from database or you will use your dataSource to send ContainerDataSource.

Vazgen Torosyan
  • 1,255
  • 1
  • 12
  • 26