문제

My project have two main requirements

1) Different set of rules applied to same object at insertion and while updating it.

2) Different validation rules based on locale.

In ADDRESS object STATE field requires different validation rules For USA: STATE cannot be NULL. For everywhere else it can be NULL.

For first requirement i am already using GROUPS. Is there a way to achieve second requirements.

I am using: Hibernate Validator 4.0.1 GA Hibernate 5.2.6

도움이 되었습니까?

해결책

This question got answered on the Hibernate Validator forum. Best way to go is a class-level constraint or a Validator instance per Locale. I really wouldn't recommend the latter, but it's a possibility.

다른 팁

I would make the country (Locale based or not is up to you) part of the Address and use a custom class-level constraint to do the validation.

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