You can use Bean Validation to constrain your data in many different ways. In this recipe, we are going to use it to validate a JSF form, so we can validate it as soon as the user tries to submit it, and avoid any invalid data right away.
Using Bean Validation for data validation
Getting ready
First, we add our dependencies:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<...