From the course: Java EE: Bean Validation
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Local custom validation failure messages
From the course: Java EE: Bean Validation
Local custom validation failure messages
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.