One of the richest features of the Bean Validation API is the ability to create your own custom constraints. Even though the built in constraints and those provided by Hibernate are quite extensive, you may find that they don't satisfy your data integrity requirements. In which case, you can create your own constraints that do just what you need.
- [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 annotation class…I need to click on the size constraint…
In this course, you can journey through the many constraints that are built into the 2.0 version of the Bean Validation API, as well as the additional constraints provided by the Hibernate Validator 6.0. Learn Bean Validation in a practical way while you build a functioning web application. Instructor Alex Theedom shows how to extend the API with custom constraints and how to internationalize validation failure messages. Plus, learn advanced techniques such as cross-field and cross-parameter validation, and how Bean Validation integrates with other Java EE technologies such as JAX-RS, Java Persistence API (JPA), and JavaServer Faces (JSF). By the end of this course, you will have gained practical experience of using Bean Validation in a real web application and be able to implement what you have learned in your own Java applications.
- What is Bean Validation?
- Applying the built-in constraints
- Applying Hibernate constraints
- Designing custom constraint validators
- Managing and configuring validation failure messages
- Creating custom composite constraints
- Creating custom validation constraints
- Cross-field and cross-parameter validation
- Integration with RESTful web services (JAX-RS)