The Bean Validation API provides a range of useful features for easily creating custom constraints which you examine in detail in this video. One of those features is composition which allows new constraints to be built on top of existing constraints. In this video, learn the structure of a custom composite constraint validator and what is required to implement one correctly. Create a composite constraint that replaces the built-in constraints that mark the price limit field.
- [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 remove the class…and I have to put in at-interface.…
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)