Here is what you should see:
User Input Validation
[ 164 ]
Looks all right, but the message for the age could be more sensible, something like
You are too young! You should be at least 5 years old.. We'll deal with this later.
However for now, enter a very long username, only two characters for password and
an age that is more than the upper limit, and see how the messages will change:
Again, looks good, except for the message about age. Next, enter some valid values
for User Name, Password and Age. Then click on the check box to subscribe to the
newsletter. In the text box for email, enter some invalid value and click on Submit.
Here is the result:
Chapter 6
[ 165 ]
Yes! The validation worked properly, but the error message is absolutely
unacceptable. Let's deal with this, but first make sure that any valid email address
will pass the validation.
Providing Custom Error Messages
We can provide custom messages for validators in the application's (or page's)
message catalog. For such messages we use keys that are made of the validated
component's ID, the name of validator and the "message" postfix. Here is an example
of what we could add to the app.properties file to change error messages for the
Min and Max validators of the Age component as well as the message used for the
email validation:
email-regexp-message=Email address is not valid.
Pages:
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214