I create simple grid with data from database:
BeanItemContainer<Customer> container = new BeanItemContainer<>(Customer.class, customerRepository.findAll());
Grid grid = new Grid(container);
To edit each row the button was created:
Button edit = new Button("Edit", clickEvent -> openWindow((Customer) grid.getSelectedRows().iterator().next()));
This open new window with edit form. After all changes accepted, I must manually refresh whole page to see modification on Grid. My question is:
How refresh only Grid after modification of any row entry? And how save those modifications to database (maybe beanItemContainer could do it)?
Since Vaadin 7.7.4 there is a
refreshRows(Object ... itemIds)
and arefreshAllRows()
method in the grid: https://dev.vaadin.com/ticket/16765With Vaadin 8, the following works to refresh the grid after rows have been added or removed or the underlying data has been changed:
It's a bug. Grid doesn't update itself after changes were done in underlying container nor has any reasonable method to refresh. There are several hacks around this issue i.e.
or
SSCCE:
Possible duplicate Update Grid with a fresh set of data, in Vaadin 7.4 app
I had to explicitly call
grid.setItems()
after each call tosaveListener
event to make my Vaadin 8.3 Grid refresh data inside the grid. It's strange that the visual grid state does not reflect edited values.Scala implementation:
There is a way to solve the problem much better:
You have to get the
BeanItem
from the container and pass this to your editor window. There you can change the bean itself by asscessing it hrough theBeanItem
sProperies
. This is a very manual work so I use instead always databindg ofFieldGroup
- just callbind
(field, "propertyName"); where propertyName is the getter method without get and non capital letter.