0

I am begine use Vaadin 7. I want use easy way to create many entity forms and tables via Vaadin 7.

And my question is Have code

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);
    }
}

And when I press button SaveEntity nothing happening - Entity not adding.

Jpa is work fine. What I am doing wrong?

jww
  • 97,681
  • 90
  • 411
  • 885
andrejs82
  • 91
  • 1
  • 6

1 Answers1

1

Are you using Vaadin 7.3 and JPAContainer 3.1.1.? Try adding userDataSource.commit(); after fieldGroup.commit();

Loxley
  • 1,781
  • 17
  • 20