summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/data
diff options
context:
space:
mode:
authorPatrik Lindström <patrik@vaadin.com>2013-07-31 16:42:16 +0300
committerVaadin Code Review <review@vaadin.com>2013-08-07 10:53:59 +0000
commit11f8811eb0f7a306c403d36ab45f5d8658d7a164 (patch)
treeda08b51e2d9c02ea2ae963792ff5ad432980d4dd /server/src/com/vaadin/data
parent8ba41172216a98a45f82319d9a98d04a26efa52a (diff)
downloadvaadin-framework-11f8811eb0f7a306c403d36ab45f5d8658d7a164.tar.gz
vaadin-framework-11f8811eb0f7a306c403d36ab45f5d8658d7a164.zip
Make sure bean field validators are only added once (#11045)
Change-Id: I67779fa5bfd4c850101c11c22091c988eb65b808
Diffstat (limited to 'server/src/com/vaadin/data')
-rw-r--r--server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
index 0b4e3a8049..cb8a044f00 100644
--- a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
+++ b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
@@ -16,6 +16,8 @@
package com.vaadin.data.fieldgroup;
import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItem;
@@ -27,9 +29,11 @@ public class BeanFieldGroup<T> extends FieldGroup {
private Class<T> beanType;
private static Boolean beanValidationImplementationAvailable = null;
+ private final Map<Field<?>, BeanValidator> defaultValidators;
public BeanFieldGroup(Class<T> beanType) {
this.beanType = beanType;
+ this.defaultValidators = new HashMap<Field<?>, BeanValidator>();
}
@Override
@@ -171,16 +175,28 @@ public class BeanFieldGroup<T> extends FieldGroup {
}
@Override
+ public void unbind(Field<?> field) throws BindException {
+ super.unbind(field);
+
+ BeanValidator removed = defaultValidators.remove(field);
+ if (removed != null) {
+ field.removeValidator(removed);
+ }
+ }
+
+ @Override
protected void configureField(Field<?> field) {
super.configureField(field);
// Add Bean validators if there are annotations
- if (isBeanValidationImplementationAvailable()) {
+ if (isBeanValidationImplementationAvailable()
+ && !defaultValidators.containsKey(field)) {
BeanValidator validator = new BeanValidator(beanType,
getPropertyId(field).toString());
field.addValidator(validator);
if (field.getLocale() != null) {
validator.setLocale(field.getLocale());
}
+ defaultValidators.put(field, validator);
}
}