Hi friend,
For dyna validation some step to be remember :
*)The form beans of DynaValidatorForm are created by Struts and you configure in the Struts config :
<form-beans >
<form-bean name="dynaValidatorForm " type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="id" type="java.lang.Integer" />
<form-property name="user" type="java.lang.String" />
</form-bean>
</form-beans>
*)The Form Bean can be used in an Action.
<action attribute="dynaValidatorForm "
input="/home.jsp"
name="dynaValidatorForm "
path="/dyna"
scope="request"
type="com.MyAction" />
*)You configure the rules for each property of a FormBean. These validations have to be written in the XML file (validation.xml)
validation.xml:
<form-validation>
<formset>
<!-- validation mapping für example form -->
<form name="dynaValidatorForm ">
<field
property="user"
depends="required, minlength">
<arg0 key="dynaValidatorForm .user" />
<arg1 key="${var:minlength}" resource="false" />
<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
*) Action class
public class MyAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
//ActionFormDynaValidatorForm zuweisen
DynaValidatorForm dynaForm = (DynaValidatorForm ) form;
//access the properties of the ActionForm
System.out.println(dynaForm .get("user"));
System.out.println(dynaForm .get("id"));
return mapping.findForward("dyna");
}
}
*) Create a Jsp page
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-html"; prefix="html"%>
<html>
<head>
<title>JSP for DynaValidator</title>
</head>
<body>
<html:form action="/dyna">
<html:errors />
Name: <html:text property="user" /> <br>
Age: <html:text property="id" /> <br>
<html:submit value="Save"/>
</html:form>
</body>
</html>
For more information on struts visit to :
http://www.roseindia.net/strutsThanks