The Bean Validation API sets default validation failure messages for validation failures. However, these messages may not be sufficient for your purposes, so you can specify your own error messages instead. In this video, look at how to create custom validation failure messages and then implement your own messages. These messages are set localling in the Java bean itself.
- [Instructor] The validation error messages can be…configured directly in the constraint annotation itself.…So let's add some custom validation messages…to the to the client bean.…So here on the screen, you can see…we have the client bean class open.…You should be familiar with this class by now,…so let's start by adding a few custom messages.…They are added to the parenthesis that follow…the constraint annotation,…and assigned to the variable message.…So the first message to add…is to the not-blank constraint on the name field.…So the message I want to display on the screen,…if a name has not been entered is something like,…please ensure you enter your name.…
Now I do this like this.…I add parenthesis, I type in message,…and then within quotes, I type in my message,…which is please ensure you enter your name.…So that's it.…Now when the form is submitted without a name…in the name field, this message will be displayed…on screen underneath a name input box.…I'm going to continue to add custom messages.…Next will be the email field.…
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)