|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2009 the original author or authors. |
| 2 | + * Copyright 2002-2010 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
23 | 23 | import javax.validation.metadata.BeanDescriptor;
|
24 | 24 | import javax.validation.metadata.ConstraintDescriptor;
|
25 | 25 |
|
| 26 | +import org.springframework.beans.NotReadablePropertyException; |
26 | 27 | import org.springframework.context.support.DefaultMessageSourceResolvable;
|
27 | 28 | import org.springframework.util.Assert;
|
28 | 29 | import org.springframework.validation.Errors;
|
@@ -76,10 +77,17 @@ public void validate(Object target, Errors errors) {
|
76 | 77 | String field = violation.getPropertyPath().toString();
|
77 | 78 | FieldError fieldError = errors.getFieldError(field);
|
78 | 79 | if (fieldError == null || !fieldError.isBindingFailure()) {
|
79 |
| - errors.rejectValue(field, |
80 |
| - violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), |
81 |
| - getArgumentsForConstraint(errors.getObjectName(), field, violation.getConstraintDescriptor()), |
82 |
| - violation.getMessage()); |
| 80 | + try { |
| 81 | + errors.rejectValue(field, |
| 82 | + violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), |
| 83 | + getArgumentsForConstraint(errors.getObjectName(), field, violation.getConstraintDescriptor()), |
| 84 | + violation.getMessage()); |
| 85 | + } |
| 86 | + catch (NotReadablePropertyException ex) { |
| 87 | + throw new IllegalStateException("JSR-303 validated property '" + field + |
| 88 | + "' does not have a corresponding accessor for Spring data binding - " + |
| 89 | + "check your DataBinder's configuration (bean property versus direct field access)", ex); |
| 90 | + } |
83 | 91 | }
|
84 | 92 | }
|
85 | 93 | }
|
|
0 commit comments