Grid + LazyLoad + Hibernate


How can i do this?

int limit = 100;
int page = 1;
int offset = (page - 1) * limit;
List<EntityUser> users = UserDatabaseAccess.getUsers(offset, limit);
Grid grid = new Grid();
grid.setContainerDataSource(new BeanItemContainer<EntityUser>(EntityUser.class, users));
grid.addScrollLoading(new LazyLoading()) {
   onScroll() {
      offset = (page - 1) * limit;
      grid.appendData(UserDatabaseAccess.getUsers(offset, limit));

Have a look at!addon/viritin and!addon/lazy-query-container


Thanks. But i want grid object, not table.

The containers are interchangeable, so you should be able to use Lazy Query Container with either grid or table instead of beanitemcontainer in your snippet above.

I’m doing lazy loading with Grid, although I’m using my own lazy-loading container instead of the add-on conntainers I linked to.


Points to the own container.
Key methods what you need to implement are
size(), getIdByIndex(int) and getItemIds(int, int)
This way you get full control of item loading and can keep container very light weight.

Please, i want some examples.

  1. how to set number of grid rows
  2. how catch scroll event of grid
  3. how apppend extra data to grid

Hi Jenk,
Number of visible rows is usually auto calculated when you use default height mode (
Calculation magic only needs number of total rows thats why it is important implementa size method to the container.
Client side Grid does call to server RPC automaticly when user scroll grid in browser up or down and fetch objects that way for object feching only thing what you have to do is just implement container and in it fetch items lazy way.

This vaadin webinar does use Table but Container usage in Table and Grid is quite same(in server side) and there is coding examples how you can implement it by using lazy-containenr