Java Reference
In-Depth Information
Figure 10.4:
Highlighting required fields with just one message at the
top
Finally, we display the global error message above the form:
Download email_19/web/WEB-INF/jsp/register.jsp
<p> Register to create an account: </p>
<s:errors globalErrorsOnly="true"/>
<s:form beanclass="stripesbook.action.RegisterActionBean">
Without any other <s:errors> tag in the page, individual required-field
error messages are not shown—just the global message. The field errors
still cause Stripes to add class= "error" to the corresponding input fields.
By having a style for this class in the CSS file, the missing fields are
automatically highlighted. That's it. We don't have to change anything
else in the JSP. Beautiful.
10.4
Using Validation Metadata
At the bottom of the registration page, the user chooses how many email
aliases they want to create. This must be a number between 0 and 5 .
That's easy enough to validate in the action bean:
Download email_19/src/stripesbook/action/RegisterActionBean.java
@Validate(required= true , minvalue=0, maxvalue=5)
private Integer numberOfAliases;
We could let users enter the number of aliases in a text box, but they
would get a validation error if they entered an invalid number or a value
 
 
 
 
Search WWH ::




Custom Search