Sometimes your business logic requires the validation of one field depends on the validation of another, especially when data entry forms have fields that depend on other fields. In this video, learn about the motivation for cross field validation and examine a few use case scenarios. In this video, implement cross field validation in the course project for a range of use cases and deploy the application and see the validation in action.
- [Narrator] Cross-parameter constraints validate…parameters to methods and constructors that…are logically connected.…Just as cross-field constraints validate the…cross-fields, cross-parameter constraints validate…the cross-parameters.…A cross-parameter constraint is set up in exactly…the same way as we have been setting up…custom constraints.…A cross-parameter constraint is setup in the same…way as the custom constraints we have been creating…during this course.…So you create an annotation for the validation…constraint and then a separate class for the…validation logic.…
The only difference is the validated class must…be annotated with a supported validation…target annotation.…This enables enables validation across parameters…and distinguishes it from return value validation.…This is because both return validation and cross…parameter validation constraints are placed…on the method.…Okay, let's have a look at some code examples.…Here's the client Bean and here is the constructor.…As you can see I've added a field confirm email.…
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)