JPAContainer's FieldFactory and Bean Validation

Hi,

I recently started using Vaadin and I guess I love it. When I eventually get a hang of it, I think it will save A LOT of my development time.

That said, I have a question / suggestion regarding the Vaadin JPAContainer and Vaadin Bean Validation addons.

Both plugins seems great, however in some instances they do not work very well together, either that or I am missing something.

Given this persistence-model:


@Entity
public class Person {
    
    @Id
    @GeneratedValue
    private long id;
    
    @Size(min=2,max=32)
    private String name;
    
    @Size(min=2,max=32)
    private String phone;

    @Size(min=2,max=32)
    private String email;
    
    @NotNull
    @OneToOne
    private Address address;

    ...
}

@Entity
public class Address {
    
    @Id
    @GeneratedValue
    private long id;
    
    @NotNull
    @Size(min=2,max=64)
    private String row1;
    
    @Size(min=2,max=64)
    private String row2;
    
    @NotNull
    @Size(min=5,max=6)
    private String zipcode;
    
    @NotNull
    @Size(min=2,max=64)
    private String city;

    ...
}

The JPAContainers FieldFactory will generate a OneToOneForm for input of the address, this form will, understandably, not have validation. Even if I generate the form like this:


        final JPAContainer<Person> container = JPAContainerFactory.makeBatchable(Person.class, PERSISTENCE_UNIT);
        container.setAutoCommit(false);
        
        final Form form = new BeanValidationForm<Person>(Person.class);
        form.setWriteThrough(false);
        form.setImmediate(true);
        form.setFormFieldFactory(new com.vaadin.addon.jpacontainer.fieldfactory.FieldFactory());
        form.setItemDataSource(container.getItem(container.addItem()));
        form.setVisibleItemProperties(new String[] {"name","phone","email","address"});
        form.getFooter().addComponent(new Button("Save", new Button.ClickListener() {
            
            public void buttonClick(ClickEvent event) {
                form.commit();
                container.commit();
            }
            
        }));
        mainWindow.addComponent(form);

On validation of the form and there’s a problem with the address, it just says that, that there’s something wrong with the address, not what’s wrong. (See screenshot)

I was looking into the FieldFactory to perhaps override the OneToOneForm-generation, unfortunately the FieldFactory requires an instance of OneToOneForm so I cannot give it a BeanValidationForm(Address.class).

Am I doing something wrong?
If not, couldn’t the OneToOneForm be an interface or does FieldFactory.createOneToOneField(EntityContainer, Object, Object, Component) really have to return a OneToOneForm? Looking at the
source
, the OneToOneForm is only referenced in that method so why not let it return a Field as the name of the method suggests?

Full test source is attached, with screenshot of validation error in form.

P.S. Why do I not seem to get a caption for my OneToOneForm? As in the screenshot on the
addon-page
.
12242.java (1.7 KB)
12243.java (1.21 KB)
12244.java (1.22 KB)
12245.png

The reason why I didn’t get the caption for the nested form was that, per default, Reindeer-theme disables all nested captions (style: .v-form-nocaption) if the parent form doesn’t have a caption. Can be resolved with a style-rule:


/*To enable ALL captions in nested forms*/
.v-form-nocaption .v-form > fieldset > legend {
	display: block;
}