From the course: Java EE: Bean Validation

Unlock the full course today

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

Motivation for custom constraints

Motivation for custom constraints

From the course: Java EE: Bean Validation

Start my 1-month free trial

Motivation for custom constraints

- [Instructor] Sometimes the built in constraints are not enough for the validation problem we want to solve. And for this reason the bean validation API makes it easy for the developer to build custom constraints. There are two ways to create your own constraint. The first way is to combine existing constraints to make a hybrid constraint. These are referred to as composite constraints. And the second way is to write a new constraint from scratch. And both ways require the construction of an annotation with certain properties that identify it as a bean validation constraint. Let's go to the IDE and dissect an already existing constraint to see what it consists of. This will help me know what I need to include in my constraint annotation when I build it. I have this doc class open in front of me and I want to look at how the size constraint has been constructed. I have this doc class open in front of me and I want to look at how the size constraint has been constructed. To open the…

Contents