age-min-message=You are too young! You should be at least 5 years
old.
age-max-message=People do not live that long!
User Input Validation
[ 166 ]
Still better, instead of hard-coding the required minimal age into the message, we
could insert into the message the parameter that was passed to the Min validator
(following the rules for java.text.Format), like this:
age-min-message=You are too young! You should be at least %s years
old.
If you run the application now and submit an invalid value for age, the error
message will be much better:
You might want to make sure that the other error messages have changed too.
We can now successfully validate values entered into separate fields, but what if
the validity of the input depends on how two or more different values relate to each
other? For example, at the Registration page we want two versions of password to
Chapter 6
[ 167 ]
be the same, and if they are not, this should be considered as an invalid input and
reported appropriately. Before dealing with this problem however, we need to look
more thoroughly at different events generated by the Form component.
Handling Validation-Related Form Events
Previously, while writing a Form submission handler, we used either an annotation
like this:
@OnEvent(value="submit", component="registrationForm")
or an appropriately named method like onSubmitFromRegistrationForm().
Pages:
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215