Pergunta

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

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top