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;
protected static class SimpleContext implements Context, Serializable {
private final Object value;
+ private final ConstraintViolation<?> violation;
private final ConstraintDescriptor<?> descriptor;
/**
*
* @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
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();
+ }
+ }
+ }
+
}
/**
.getMessageInterpolator()
.interpolate(violation.getMessageTemplate(),
new SimpleContext(value,
- violation.getConstraintDescriptor()),
+ violation),
locale);
causes[i] = new InvalidValueException(msg);
++i;
<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>
<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>
<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>
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