turn NotReadablePropertyException into JSR-303 oriented IllegalStateException
This commit is contained in:
parent
4cef52a86f
commit
5f9b2db90b
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -23,6 +23,7 @@ import javax.validation.ConstraintViolation;
|
||||||
import javax.validation.metadata.BeanDescriptor;
|
import javax.validation.metadata.BeanDescriptor;
|
||||||
import javax.validation.metadata.ConstraintDescriptor;
|
import javax.validation.metadata.ConstraintDescriptor;
|
||||||
|
|
||||||
|
import org.springframework.beans.NotReadablePropertyException;
|
||||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
|
|
@ -76,11 +77,18 @@ public class SpringValidatorAdapter implements Validator, javax.validation.Valid
|
||||||
String field = violation.getPropertyPath().toString();
|
String field = violation.getPropertyPath().toString();
|
||||||
FieldError fieldError = errors.getFieldError(field);
|
FieldError fieldError = errors.getFieldError(field);
|
||||||
if (fieldError == null || !fieldError.isBindingFailure()) {
|
if (fieldError == null || !fieldError.isBindingFailure()) {
|
||||||
|
try {
|
||||||
errors.rejectValue(field,
|
errors.rejectValue(field,
|
||||||
violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(),
|
violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(),
|
||||||
getArgumentsForConstraint(errors.getObjectName(), field, violation.getConstraintDescriptor()),
|
getArgumentsForConstraint(errors.getObjectName(), field, violation.getConstraintDescriptor()),
|
||||||
violation.getMessage());
|
violation.getMessage());
|
||||||
}
|
}
|
||||||
|
catch (NotReadablePropertyException ex) {
|
||||||
|
throw new IllegalStateException("JSR-303 validated property '" + field +
|
||||||
|
"' does not have a corresponding accessor for Spring data binding - " +
|
||||||
|
"check your DataBinder's configuration (bean property versus direct field access)", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue