From the course: Java EE: Bean Validation

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Advanced constraint usage

Advanced constraint usage

From the course: Java EE: Bean Validation

Start my 1-month free trial

Advanced constraint usage

- [Narrator] Bean Validation constraints annotate fields of a class. And when they do, the value of the field is accessed directly by the validation engine. It's important to know that if a field has the corresponding accessor method, then this method will not be called regardless of the accessor modifier of the Bean's fields. Now, all access modifiers are supported, except static fields. Constraints can also annotate methods of Beans, as long as those methods and your Bean actually conform to the JavaBean standard. The accessor method must be annotate, not the mutator method. So, the read-only properties can be accessed. In the case of property-level constraints, the Bean Validation engine doesn't actually cause the accessor method, and does not access the field directly. Container elements can also be annotated with a Bean Validation constraint. This is done by annotating the parameterized type argument of the container. So, it can be used on list types, and be used on set types. It…

Contents