Java Reference
In-Depth Information
Return to source page,
display error messages
Browser
request
validation
errors
Action Bean
parameter
binding
Validation
no validation
errors
Execute event handler
Figure 4.1: The validation sequence
We now have a clearly defined validation for the age property. Submit-
ting the form with the Age field left blank, or filled in with a value less
than eighteen, produces a validation error. As illustrated in Figure 4.1 ,
Stripes does not execute the intended event handler when a validation
error occurs. Instead, the user is sent back to the form that was sub-
mitted. This way, we can safely save data in the event handler method
because we know that Stripes won't call it if the data is invalid. All
we need to do is to add the <s:errors> tag to our JSP to display error
messages, and we're done!
Nested Properties
@Validate works only in an action bean. Annotating properties of a plain
model class won't work, because Stripes doesn't go searching for anno-
tations in model classes. Does this mean you have to copy properties
from a model class to an action bean? Of course not—that wouldn't be
very Stripesy! Just like forms, validations support nested properties. 1
Remember
that
a
nested
property
is
a
property
of
a
property,
such
as
1.
getPer-
son().getAge() .
 
 
 
Search WWH ::




Custom Search