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.

Creating custom composite constraints

Creating custom composite constraints

From the course: Java EE: Bean Validation

Start my 1-month free trial

Creating custom composite constraints

- [Instructor] So, let's jump right back into the code and create a composite constraint. If you remember, a composite constraint is built from already existing constraints, so it makes sense to look through the project's code to find where I am already using multiple annotations on a single field, and replace it with a custom composite constraint. I know that the transaction class has a field called price limit that has three constraints on it. Now, I want to replace those three constraints with just one composite constraint, which I think I'll call price limit. So, I'm going to create an annotation and I'm going to call it price limit. In order to organize my constraints, I will create a new package called constraints in the model package. So, I'll just go over here, new package, and just call it constraints. Now I need to create my constraint. That's new, Java class, and my new constraint is going to be called price limit. Now remember, in order to create an annotation I have to…

Contents