Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Validation > Using Visitor Field Validator |
The followings show a simple example using Webwork's Field Validators
Create the jsp page
<s:fielderror /> <s:form method="POST" action="submitVisitorValidatorsExamples" namespace="/validation"> <s:textfield name="user.name" label="User Name" /> <s:textfield name="user.age" label="User Age" /> <s:textfield name="user.birthday" label="Birthday" /> <s:submit label="Submit" /> </s:form>
Create the actoin class
public class VisitorValidatorsExampleAction extends AbstractValidationActionSupport { private static final long serialVersionUID = 4375454086939598216L; private User user; public User getUser() { return user; } public void setUser(User user) { this.user = user; } }
Create the validator.xml.
<validators> <field name="user"> <field-validator type="visitor"> <param name="context">userContext</param> <param name="appendPrefix">true</param> <message>User:</message> </field-validator> </field> </validators>