Java Reference
In-Depth Information
wouldn't be nice to welcome the user to the form with validation error
messages! With
on=
"save", required-field validations are restricted to
save
( ) and so do not cause errors in
form
( ).
Once in the form, the user may very well enter invalid values and then
click the
Cancel
button. You need to turn off all validations by anno-
tating
cancel
( ) with
@DontValidate
so that the user will be allowed to
cancel the form even if the input is not valid.
Whew. . . enough theory. Let's look at some examples.
4.2
Using Built-in Validations
Let's get back to our webmail application. We have a form to enter a
contact's information, displayed by
contact_form.jsp
:
<s:form beanclass="${actionBean.class}">
<div><s:hidden name="contact.id"/></div>
<table class="form">
<tr>
<td>
Email:
</td>
<td>
<s:text name="contact.email" class="required"/>
</td>
</tr>
<!--Same for First and Last name, Phone number, Birth date-->
<tr>
<td>
</td>
<td>
<s:submit name="save" value="Save"/>
<s:submit name="cancel" value="Cancel"/>
</td>
</tr>
</table>
</s:form>
ContactFormActionBean
sends the user to the form and handles the form
submission:
package
stripesbook.action;
public class
ContactFormActionBean
extends
ContactBaseActionBean {
private static final
String FORM="/WEB-INF/jsp/contact_form.jsp";
@DefaultHandler
public
Resolution form() {
return new
ForwardResolution(FORM);
}
Search WWH ::
Custom Search