Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen on save button or assign an event after it was clicked in Vaadin 7

Tags:

java

vaadin

When I am editing grid inline I can save or cancel my grid row changes. I want to update my database entries after button 'save' will be pushed(Data base mechanism has already done) How can I implement it?

My container: BeanItemContainer<CategoryOfService> beansContainer;

Editing view: enter image description here

All what I need it know which listeners I have to use. I found some CommitHandler which I can add by EditorFieldGroup class but I can't implement it properly maybe there is have to be another way to resolve problem.

like image 397
viavad Avatar asked Jul 05 '15 16:07

viavad


2 Answers

There's kind of a way to capture inline Save click on the grid.

grid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() {
        @Override
        public void preCommit(FieldGroup.CommitEvent commitEvent) throws     FieldGroup.CommitException {
        //...
        }

        @Override
        public void postCommit(FieldGroup.CommitEvent commitEvent) throws     FieldGroup.CommitException {
        //...
        }
});

After clicking Save both methods preCommit and postCommit get called.

Hope it helps :)

like image 123
jrf Avatar answered Nov 05 '22 09:11

jrf


Grid does not currently give you any direct way of adding listeners to the save and cancel buttons for the inline editor, although that is something that might change in Vaadin 7.6.

As a workaround before that happens, the CommitHandler approach that you already mentioned is still supposed to work. You can find a basic example here. The contents of your BeanItemContainer should be fully updated in the postCommit phase.

like image 23
Leif Åstrand Avatar answered Nov 05 '22 11:11

Leif Åstrand