0

我开始使用 Vaadin 7。我想使用简单的方法通过 Vaadin 7 创建许多实体表单和表格。

我的问题是有代码

package com;

import com.vaadin.addon.jpacontainer.JPAContainer;
import com.vaadin.addon.jpacontainer.JPAContainerFactory;
import com.vaadin.data.fieldgroup.FieldGroup;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.*;

public class TestVaadinApplication extends UI {

    @Override
    protected void init(VaadinRequest request) {
        VerticalLayout tableLayout = new VerticalLayout();

        final Table table = new Table("table with data from JPAContainer");
        final JPAContainer<UserEntity> userDataSource = JPAContainerFactory.makeJndi(UserEntity.class);
        table.setContainerDataSource(userDataSource);
        table.setSizeFull();
        tableLayout.addComponent(table);
        tableLayout.addComponent(new Button("add user entity", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {

                final Window editEntityWindow = new Window();
                editEntityWindow.setModal(true);
                editEntityWindow.setClosable(true);
                final FieldGroup fieldGroup = new FieldGroup(userDataSource.createEntityItem(new UserEntity()));
                FormLayout formLayout = new FormLayout();
                formLayout.addComponent(fieldGroup.buildAndBind("nameCaption", "name"));
                formLayout.addComponent(fieldGroup.buildAndBind("loginCaption", "login"));
                formLayout.addComponent(new Button("SaveEntity", new Button.ClickListener() {
                    @Override
                    public void buttonClick(Button.ClickEvent event) {
                        try {
                            fieldGroup.commit();
                            editEntityWindow.close();
                            table.refreshRowCache();
                        } catch (FieldGroup.CommitException e) {
                            e.printStackTrace();
                            Notification.show("Error!", Notification.Type.ERROR_MESSAGE);
                        }
                    }
                }));

                editEntityWindow.setContent(formLayout);

                TestVaadinApplication.this.addWindow(editEntityWindow);
            }
        }));


        setContent(tableLayout);
    }
}

当我按下按钮 SaveEntity 时,什么也没有发生 - 实体没有添加。

Jpa 工作正常。我做错了什么?

4

1 回答 1

1

您使用的是 Vaadin 7.3 和 JPAContainer 3.1.1 吗?尝试 userDataSource.commit(); 在 fieldGroup.commit(); 之后添加

于 2014-09-26T11:04:03.723 回答