|
|
|
@ -22,6 +22,7 @@ import javax.validation.metadata.BeanDescriptor; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.validation.Errors; |
|
|
|
import org.springframework.validation.Errors; |
|
|
|
|
|
|
|
import org.springframework.validation.FieldError; |
|
|
|
import org.springframework.validation.Validator; |
|
|
|
import org.springframework.validation.Validator; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -68,10 +69,14 @@ public class SpringValidatorAdapter implements Validator, javax.validation.Valid |
|
|
|
public void validate(Object target, Errors errors) { |
|
|
|
public void validate(Object target, Errors errors) { |
|
|
|
Set<ConstraintViolation<Object>> result = this.targetValidator.validate(target); |
|
|
|
Set<ConstraintViolation<Object>> result = this.targetValidator.validate(target); |
|
|
|
for (ConstraintViolation<Object> violation : result) { |
|
|
|
for (ConstraintViolation<Object> violation : result) { |
|
|
|
errors.rejectValue(violation.getPropertyPath().toString(), |
|
|
|
String field = violation.getPropertyPath().toString(); |
|
|
|
violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), |
|
|
|
FieldError fieldError = errors.getFieldError(field); |
|
|
|
violation.getConstraintDescriptor().getAttributes().values().toArray(), |
|
|
|
if (fieldError == null || !fieldError.isBindingFailure()) { |
|
|
|
violation.getMessage()); |
|
|
|
errors.rejectValue(field, |
|
|
|
|
|
|
|
violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), |
|
|
|
|
|
|
|
violation.getConstraintDescriptor().getAttributes().values().toArray(), |
|
|
|
|
|
|
|
violation.getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|