简体   繁体   English

如何在Vaadin 7中单击保存按钮或指定事件后进行分配

[英]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? 我想在按下'save'按钮后更新我的数据库条目(数据库机制已经完成)我该如何实现它?

My container: BeanItemContainer<CategoryOfService> beansContainer; 我的容器: 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. 我找到了一些我可以通过EditorFieldGroup类添加的CommitHandler,但是我无法正确实现它可能必须有另一种方法来解决问题。

There's kind of a way to capture inline Save click on the grid. 有一种方法可以捕获内联Save点击网格。

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. 单击Save两个方法都会调用preCommit和postCommit。

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. Grid目前没有为您提供任何直接的方法来将监听器添加到内联编辑器的保存和取消按钮,尽管这可能会在Vaadin 7.6中发生变化。

As a workaround before that happens, the CommitHandler approach that you already mentioned is still supposed to work. 作为一种解决方法,在此之前,您已经提到的CommitHandler方法仍然可以工作。 You can find a basic example here . 你可以在这里找到一个基本的例子。 The contents of your BeanItemContainer should be fully updated in the postCommit phase. BeanItemContainer的内容应该在postCommit阶段完全更新。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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