Java Reference
In-Depth Information
Figure 4.6: A validation error using a regular expression mask
Pretty good. We've added validation to the contact form, and all we
needed were annotations in the action bean and a single <s:errors/>
tag in the JSP.
We didn't use the minimum/maximum numerical value and credit card
validations in the contact form because we don't have any fields that
are relevant to those validations. Nevertheless, let's look at them briefly
before continuing.
Minimum and Maximum Numerical Values
Stripes provides validation of minimum and maximum numerical val-
ues with the minvalue= and maxvalue= attributes of @Validate . These
attributes accept values of type double , and they work for properties
of any primitive numerical type as well as all subclasses of Number .
Suppose you wanted to restrict some field to a value between 0 and 7 ,
inclusive. You would use this:
@Validate(minvalue=0, maxvalue=7)
private int someField;
Now, entering an invalid value for this field would give an error message
such as this:
• “The minimum allowed value for Some Field is 0.”
• “The maximum allowed value for Some Field is 7.”
Again, Stripes is smart enough to use the values that we specify in the
minvalue= and maxvalue= attributes to construct the error messages.
 
 
 
Search WWH ::




Custom Search