In this video, implement some of the most useful constraints provided by the Hibernate Validator Bean Validation implementation.
- Okay, so lets add the credit card constraint…to the credit card field in the client bean.…So, I'm just going to navigate to the client bean,…which, you'll remember, is in the model package,…and let's just scroll down to where the credit card is.…This is quite a simple constraint, and has only one flag,…the Ignore Non-Digit Characters flag,…that when set to true, will ignore dashes, spaces,…slashes in the credit card number entered.…Okay, so let's enter than right now.…@CreditCard, okay.…
And then, we're going to pass into it the flag,…and set the flag.…In this case, I want the flag to be true,…because I want to be able to enter slashes and spaces…in my credit card number.…Okay, so let's go to the test class.…So, as you can see, I have four empty tests.…The first test tests whether the number is invalid,…the next one tests if the number is valid,…then the third test tests to make sure…that dashes are acceptable,…and then the final one tests to make sure that…if it's null, it's not acceptable, either.…
Okay, so let's get started with the first test.…
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)