diff options
4 files changed, 41 insertions, 7 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/validator/BeanValidator.java b/compatibility-server/src/main/java/com/vaadin/v7/data/validator/BeanValidator.java index 48bb16753f..49ba4bd69d 100644 --- a/compatibility-server/src/main/java/com/vaadin/v7/data/validator/BeanValidator.java +++ b/compatibility-server/src/main/java/com/vaadin/v7/data/validator/BeanValidator.java @@ -23,6 +23,7 @@ import java.util.Set; import javax.validation.ConstraintViolation; import javax.validation.MessageInterpolator.Context; import javax.validation.Validation; +import javax.validation.ValidationException; import javax.validation.ValidatorFactory; import javax.validation.metadata.ConstraintDescriptor; @@ -67,6 +68,7 @@ public class BeanValidator implements Validator { protected static class SimpleContext implements Context, Serializable { private final Object value; + private final ConstraintViolation<?> violation; private final ConstraintDescriptor<?> descriptor; /** @@ -74,13 +76,20 @@ public class BeanValidator implements Validator { * * @param value * value being validated - * @param descriptor - * ConstraintDescriptor corresponding to the constraint being + * @param violation + * ConstraintViolation corresponding to the constraint being * validated */ + public SimpleContext(Object value, ConstraintViolation<?> violation) { + this.value = value; + this.violation = violation; + this.descriptor = violation.getConstraintDescriptor(); + } + public SimpleContext(Object value, ConstraintDescriptor<?> descriptor) { this.value = value; this.descriptor = descriptor; + this.violation = null; } @Override @@ -93,6 +102,21 @@ public class BeanValidator implements Validator { return value; } + @Override + public <T> T unwrap(Class<T> type) { + if (violation != null) { + return violation.unwrap(type); + } else { + try { + return type.newInstance(); + } catch (InstantiationException e) { + throw new ValidationException(); + } catch (IllegalAccessException e) { + throw new ValidationException(); + } + } + } + } /** @@ -128,7 +152,7 @@ public class BeanValidator implements Validator { .getMessageInterpolator() .interpolate(violation.getMessageTemplate(), new SimpleContext(value, - violation.getConstraintDescriptor()), + violation), locale); causes[i] = new InvalidValueException(msg); ++i; @@ -30,7 +30,7 @@ <vaadin.plugin.version>8.7-SNAPSHOT</vaadin.plugin.version> <!-- Used in OSGi manifests --> - <javax.validation.version>1.0.0.GA</javax.validation.version> + <javax.validation.version>2.0.1.Final</javax.validation.version> <jsoup.version>1.11.2</jsoup.version> <javax.portlet.version>2.0</javax.portlet.version> <vaadin.sass.version>0.9.13</vaadin.sass.version> @@ -229,7 +229,7 @@ <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> - <version>4.3.2.Final</version> + <version>5.3.5.Final</version> </dependency> <dependency> <groupId>org.jsoup</groupId> @@ -357,6 +357,12 @@ <artifactId>hibernate-validator</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.glassfish</groupId> + <artifactId>javax.el</artifactId> + <version>3.0.0</version> + <scope>test</scope> + </dependency> </dependencies> <build> <pluginManagement> diff --git a/server/src/main/java/com/vaadin/data/validator/BeanValidator.java b/server/src/main/java/com/vaadin/data/validator/BeanValidator.java index 9084e1eed6..64b96ed06a 100644 --- a/server/src/main/java/com/vaadin/data/validator/BeanValidator.java +++ b/server/src/main/java/com/vaadin/data/validator/BeanValidator.java @@ -69,6 +69,10 @@ public class BeanValidator implements Validator<Object> { return violation.getInvalidValue(); } + @Override + public <T> T unwrap(Class<T> type) { + return violation.unwrap(type); + } } private String propertyName; diff --git a/server/src/test/java/com/vaadin/data/validator/BeanValidatorTest.java b/server/src/test/java/com/vaadin/data/validator/BeanValidatorTest.java index f595be14bc..4abe08d24c 100644 --- a/server/src/test/java/com/vaadin/data/validator/BeanValidatorTest.java +++ b/server/src/test/java/com/vaadin/data/validator/BeanValidatorTest.java @@ -60,8 +60,8 @@ public class BeanValidatorTest extends ValidatorTestBase { public void testInvalidDecimalsFailsInFrench() { setLocale(Locale.FRENCH); BeanValidator v = validator("decimals"); - assertFails("1234.567", "Valeur numérique hors limite " - + "(<3 chiffres>.<2 chiffres> attendus)", v); + assertFails("1234.567", "valeur numérique hors limite " + + "(<3 chiffres>.<2 chiffres> attendu)", v); } @Test |