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

3

7

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.

Godly answered 5/7, 2015 at 16:56 Comment(1)
In Vaadin you normally have a container which handles the updates to the database. So you will have to look at the events of the BeanItemContainerMike
C
12

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 :)

Coma answered 4/5, 2016 at 20:39 Comment(1)
thanks mate. I noticed that in my case, I needed to addCommitHandler whenever I call grid.removeAllItems() then grid.setValues().Rock
R
1

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.

Rutilant answered 6/7, 2015 at 6:26 Comment(0)
S
0
grid.getEditor().addSaveListener((EditorSaveListener<Product>) event -> {
        //your stuf
        HibernateDataSource.updateProduct(event.getBean());
    });
Snubnosed answered 7/5, 2018 at 6:32 Comment(1)
Little explanation would be useful for OP.Fancied

© 2022 - 2024 — McMap. All rights reserved.