Getting Started with the Validator Framework

Getting Started with the Validator Framework

Previous Home Next

 

The goal of this chapter the started the validator framework. You have configured the Validator Plug-In in struts-config.xml files and validate="true" in action mapping.

 
Your Form class is extends org.apache.struts.validator.action.ValidatorForm instead of org.apache.struts.action.ActionForm. The Validation mechanism should have support for internationalization and be extenssible.

To use validator Framework ,follow these step :-

1. Create  an ActionForm class which class is subclass ValidatorForm.
2. Create an Action class which class is subclass Action class.
3. Create an Input jsp.
4. Add validator plugin to the struts-config.xml files.
5. Set validate="true" in action mapping.
6. Create the validation.xml file into WEB-INF.
7.  Add a form to the form set in validation.xml.
8.  Add the Error message to the resources bundle.

Example :-

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans > 
<form-bean name="userForm" type="r4r.co.in.RegisterationForm" />  
</form-beans>
<action-mappings>
<action input="/register.jsp" name="userForm" path="/Register" 
scope="request" type="r4r.co.in.RegisterationAction" validate="true" >
<forward name="success" path="/thanx.jsp"/>
</action>
</action-mappings> 
<message-resources parameter="r4r.co.in.ApplicationResources" /> 
<plug-in className="org.apache.struts.validator.ValidatorPlugIn"> 
<set-property property="pathnames"  
value="/org/apache/struts/validator/validator-rules.xml, /WEB-INF/validation.xml"/>   
</plug-in>
</struts-config>


Previous Home Next