Java Reference
In-Depth Information
Supported type
java.util.Date and
This ensures that the date
contained in the object is later
than the date of treatment
This ensures that value of the
item meets the regular expres-
sion defined in the annotation
One advantage of this specification is the ability to define the different constraints it
offers via annotations, which facilitates its use. According to the characteristics of the
annotation (explained in detail in Chapter 7 , Annotations and CDI ), you can express
constraints for a class, field, or property. The following example shows a Student
entity whose fields are decorated with the built-in constraints. You can see the con-
straints to avoid the null value or to define the size and format of attributes in the
following code:
public class Student implements Serializable {
@Size(min = 1, max = 15)
private String id;
@Size(max = 30)
private String firstname;
]?(\\d{3})[- ]?(\\d{4})$", message="Invalid
phone/fax format,should be as xxx-xxx-xxxx")
//if the field contains phone or fax number
consider using this//annotation to enforce
field validation
@Size(max = 10)
Search WWH ::

Custom Search