Refresh grid content, how to do it?

Hi,
I’m hitting a problem that I don’t know how to overcome.
I have a grid (called from a crudview) bound to a table on my database:



public class PublishersGrid extends Grid {
public PublishersGrid() {
setSizeFull();
setSelectionMode(SelectionMode.SINGLE);
BeanItemContainer container = new BeanItemContainer(Publishers.class);
setContainerDataSource(container);
setColums();
}

}

The Publishers class is bound to the right table on the DB, it works fine, righr data is shown, all CRUD operations works well.
The question is: if for some reason the data on DB change
how can I refresh the grid?

Just to be clear, I’m not asking how to fire events.
I guess I need to reload somehow the BeanItemContainer object and then tell the grid to refresh (markAsDirty method maybe?).
Thanks in advance for any hint.

To refresh the grid just do a container.removeAllItems() and container.addAll(…)

Yes, thanks Marco (grazie).
It works… almost: the grid do the refresh, but the EntityManager query return the same data as before, although they are changed.
But this is another story, I need to investigate and study on this matter.
The grid itself perform what I was asking.
Thank you again.

Just to update the whole issue:
In order to refresh the grid, in case some changes happens in the background, you also need two more things:

  • call the method [font=courier new]
    .getCache().evictAll(); [font=arial]
    in the object representing the Entity Manager Factory
  • create a new Entity Manager object (athought you have already one) from the E M Factory
    [/font]
    [/font]
    and then obvioulsly call the query again.

Happy Vaadin coding.

It seems I have ran into the same problem as you. I figured out how to get my grid to show updated data. I unload the BeanItemContaner and throw a whole new list of entities into it. Works fine, however the problem is when I use the event handler

// selection area event handlers
this.departments.addSelectionListener(event → {
DepartmentManagerViewImpl.this.presenter.editSelectionChanged(DepartmentManagerViewImpl.this.departments.getSelectedRow());
});

The getSelectedRow() method is ALWAYS returning the very first version of the populated object. I suspected some sort of cache problem so I was delighted to find your last post Sascha. However when you called .getCache().evictAll() what object exactly were you calling it on? Which enitity manager are you refering to? Are there vaadin specific entity managers which you are refering to, or are you refering to any caching or enitity managers that might exist in the rest of our stack?

EDIT: I solved my problem by modifying the entity equals method to include entity version.