Java Reference
In-Depth Information
private String phone;
//if the field contains email address
consider using this//annotation to enforce
field validation
@Size(max = 60)
private String email;
Once the constraints are defined, the Bean Validation Specification allows you to
validate the data under constraints manually or automatically through other specific-
ations. We begin by presenting manual validation. The following example demon-
strates how to validate the constraints of a class manually. We must say that the
Validator API also provides methods to validate a single attribute or a specific
value as shown in the following code:
public static void main(String[] args) {
Student student = new Student();
ValidatorFactory factory
Validator validator = factory.getValidator();
Set<ConstraintViolation<Student>> violations
System.out.println("Number of violations :
for(ConstraintViolation<Student> cons :
Search WWH ::

Custom Search