Java Reference
In-Depth Information
Figure 4.4: A validation error for minimum input length
Of course, the validation in the action bean is still executed—we can't
rely only on client-side validation, because users could sent input in
other ways than using the form. It's still nice to immediately let the
well-intentioned user know when they've reached the limit as they are
typing a value into the text field.
Another nice feature is that Stripes does not stop at the first encoun-
tered validation error. Instead, as many errors as possible are accumu-
lated during the validation process to provide more information to the
user.
Validating with EL Expressions
We can also validate user input by using an EL expression in the expres-
sion= attribute of @Validate . The boolean value of the expression deter-
mines whether the validation passed. This gives us an easy way to add
a validation based on a conditional expression.
Within the expression, we can refer to the field that we are validating
using the keyword this and to other properties of the action bean by their
names. The action bean context, the request scope, and the session
scopes are available with context , request , and session .
The birth date already benefits from the implicit validation of converting
the input to a java.util.Date . Now that we've added the <s:errors/> tag to
the JSP, the user sees an error message after entering an invalid date.
Let's use an expression to also validate that the birth date in the contact
 
 
 
Search WWH ::




Custom Search