문제

I'm using Bean Validation with Hibernate Validator.

How can I tell Hibernate to only validate a certain value of a different value passed the validator before?

@Digits //eg: DDMMYYYY
String dateString;

//this would throw an exception if @Digits fails. How can I stop validation then?
@Future
Date getDate() {
    //formatter: DDMMYYYY
    return formatter.parse(dateString);
}
도움이 되었습니까?

해결책

You could assign the constraints to different groups and then define a group sequence. If you then request the group sequence to be validated (as part of Validator#validate), constraints are validated in the defined order and validation also stops on the first error. See also http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#d0e2804.

Also, I would not use @Digit on the dateString, but @Pattern. Also you seem to annotate fields and getters. It is really recommended to stick to one approach.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top