summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2011-12-19 17:00:47 +0200
committerArtur Signell <artur@vaadin.com>2011-12-19 17:01:44 +0200
commit884d029ca78a3c198611feca9fd0a739ebc1e3d1 (patch)
treeb36cd726e264656cd35816f7cf542fcbfc6bf165 /src/com/vaadin
parent1dbec3df48796a8f129f1adf6bf5a0d71c8509ad (diff)
downloadvaadin-framework-884d029ca78a3c198611feca9fd0a739ebc1e3d1.tar.gz
vaadin-framework-884d029ca78a3c198611feca9fd0a739ebc1e3d1.zip
#8093 Ensure that property id is a non-null String. Cache if Bean
Validation implementation is available or not to avoid multiple lookups.
Diffstat (limited to 'src/com/vaadin')
-rw-r--r--src/com/vaadin/data/validator/BeanValidationValidator.java32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/com/vaadin/data/validator/BeanValidationValidator.java b/src/com/vaadin/data/validator/BeanValidationValidator.java
index e144018698..37ad67886c 100644
--- a/src/com/vaadin/data/validator/BeanValidationValidator.java
+++ b/src/com/vaadin/data/validator/BeanValidationValidator.java
@@ -45,6 +45,7 @@ public class BeanValidationValidator implements Validator {
private static final long serialVersionUID = 1L;
private static ValidatorFactory factory;
+ private static Boolean implementationAvailable = null;
private transient javax.validation.Validator javaxBeanValidator;
private String propertyName;
@@ -108,6 +109,10 @@ public class BeanValidationValidator implements Validator {
*/
public static BeanValidationValidator addValidator(Field field,
Object objectPropertyId, Class<?> beanClass) {
+ if (objectPropertyId == null || !(objectPropertyId instanceof String)) {
+ throw new IllegalArgumentException("Property id must be a non-null String");
+ }
+
String propertyId = (String) objectPropertyId;
BeanValidationValidator validator = new BeanValidationValidator(
beanClass, propertyId);
@@ -174,10 +179,11 @@ public class BeanValidationValidator implements Validator {
List<String> exceptions = new ArrayList<String>();
for (Object v : violations) {
final ConstraintViolation<?> violation = (ConstraintViolation<?>) v;
- String msg = getJavaxBeanValidatorFactory().getMessageInterpolator().interpolate(
- violation.getMessageTemplate(),
- new SimpleContext(value, violation
- .getConstraintDescriptor()), locale);
+ String msg = getJavaxBeanValidatorFactory()
+ .getMessageInterpolator().interpolate(
+ violation.getMessageTemplate(),
+ new SimpleContext(value, violation
+ .getConstraintDescriptor()), locale);
exceptions.add(msg);
}
StringBuilder b = new StringBuilder();
@@ -226,8 +232,9 @@ public class BeanValidationValidator implements Validator {
throw new InvalidValueException(
"Annotation must have message attribute");
}
- String msg = getJavaxBeanValidatorFactory().getMessageInterpolator().interpolate(
- messageTemplate, new SimpleContext(value, d), locale);
+ String msg = getJavaxBeanValidatorFactory()
+ .getMessageInterpolator().interpolate(messageTemplate,
+ new SimpleContext(value, d), locale);
exceptions.add(msg);
}
}
@@ -281,11 +288,14 @@ public class BeanValidationValidator implements Validator {
}
public static boolean isImplementationAvailable() {
- try {
- getJavaxBeanValidatorFactory();
- return true;
- } catch (Exception e) {
- return false;
+ if (implementationAvailable == null) {
+ try {
+ getJavaxBeanValidatorFactory();
+ implementationAvailable = true;
+ } catch (Exception e) {
+ implementationAvailable = false;
+ }
}
+ return implementationAvailable;
}
} \ No newline at end of file