Hello,
I’m using Vaadin 7.0.0.beta11. I have a Form with BeanFieldGroup. It seems that validator instances are added to field every time fieldGroup.setItemDataSource() is called.
I’m using setItemDataSource() calls to change data bound to a form. The use case is that I have table that displays some bean data, and when I click on table row, all bean data should appear in a form for edit. So, in table’s itemClick() handler I do: fieldGroup.setItemDataSource(event.getItem()); The problem is, that for every click, another validator gets added for every field in the form.
I have created simple example to reproduce:
public class HelloWorld extends UI {
private static final long serialVersionUID = 1L;
@Override
protected void init(VaadinRequest request) {
VerticalLayout content = new VerticalLayout();
setContent(content);
final BeanFieldGroup<TestBean> fieldGroup = new BeanFieldGroup<TestBean>(TestBean.class);
final FormLayout form = new FormLayout();
form.addComponent(fieldGroup.buildAndBind("Name", "name"));
content.addComponent(form);
fieldGroup.setItemDataSource(new TestBean());
fieldGroup.setItemDataSource(new TestBean());
}
public static class TestBean {
@Size(min = 0, max = 5)
private String name = "";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
The two calls to “fieldGroup.setItemDataSource(new TestBean());” will result in 2 validators added to form item, and 2 validator messages will be displayed on validation error.
Am I doing something wrong here?
Thanks.