Search code examples
gridvaadinvaadin8

Vaadin 8 Grid EditorSaveListener


In Vaadin 8, given the following Grid definition:

    grid = new Grid<>();
    grid.getEditor().setEnabled(true);
    carBinder = grid.getEditor().getBinder();

with:

    grid.getEditor().addSaveListener(event -> {
    try {
        Binder<Car> binder = event.getSource().getBinder();
        grid.getDataProvider().refreshAll();
    } catch(Exception e) 
        ExceptionNotification.show(e);
    }
    });

The problem I have, I currently cannot access the modified value from the Grid Editor, neither over event.getSource() nor over the binder, defined locally or in class scope.

In the debugger, I see in the Vaadin class com.vaadin.ui.components.grid.EditorImpl a property edited, containing the values, but is private, so not accessible.

The binder.bean value is NULL, in the debug. This would be the value retrieved by: binder.getBean().

So I tried many ways, but currently I could not get the edited value with the save listener, for working with it, and search some help or inspiration for solving the problem.


Solution

  • To get the values use:

    binder.writeBean(aCarObject);
    

    According to the documentation it writes the values of the fields into the given object, but throws an exception if any of the fields is invalid.