Java Reference
In-Depth Information
Figure 4.3: A validation error for a required field
As we discussed, the on= "save" restricts the validation to the save ( )
event handler. Now, if the user saves the form with the email field left
blank, a validation error occurs, and Stripes redisplays contact_form.jsp .
To show the error message to the user as in Figure 4.3 , add the
<s:errors/> tag:
Download email_06/web/WEB-INF/jsp/contact_form.jsp
<s:form beanclass="${actionBean.class}">
<s:errors/>
<div><s:hidden name="contact.id"/></div>
<table class="form">
Just like information messages, Stripes has a default way of displaying
error messages: with a header message followed by the validation errors
in a numbered list. A reasonable effort is made to construct error mes-
sages using the name of the field and the type of validation that failed,
so we get something quite decent just by adding the <s:errors/> tag. In
Chapter 6 , Customizing Stripes Messages, on page 121 , we'll talk about
how to customize both the text and the presentation of error messages.
Email Addresses
We've made the email a required field, but this validates only that the
user entered something in the field. It does not actually validate what
the user entered. How about making sure that the email format is valid?
 
 
 
 
Search WWH ::




Custom Search