简体   繁体   中英

How to listen on save button or assign an event after it was clicked in Vaadin 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: 在此输入图像描述

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.

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

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.

grid.getEditor().addSaveListener((EditorSaveListener<Product>) event -> {
        //your stuf
        HibernateDataSource.updateProduct(event.getBean());
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM