With a DynaActionForm, instead of writing classes that extend ActionForm, you define all your form beans as DynaActionForm, and define the properties for each form in the struts-config.xml file.
DynaValidatorForm will process validations defined in the Struts Validator Framework, whereas DynaActionForm will not.
They both require properties to be defined in the struts-config.xml file.
DynaActionForm
struts-config.xml
<form-beans >
<form-bean name="exampleForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="age"
type="java.lang.Integer" initial="23" />
<form-property name="name"
type="java.lang.String" initial="Adam Weisshaupt" />
</form-bean>
</form-beans>
Use of DynaActionForm in Actions
DynaActionForm exampleForm = (DynaActionForm) form;
System.out.println(exampleForm.get("name"));
DynaValidatorForm
The form bean DynaValidatorForm is the dynamic variant of the ValidatorForm and offers the possibility to validate properties based on validation rules.
The form bean DynaValidatorForm uses the Struts validation capabilities using validation rules defined in XML files. Struts offers a wide choice of rules, you can all find in the file validator-rules.xml.
You configure the rules foreach property of a FormBean.
These validations have to be written in the XML file (validation.xml)
struts-config.xml
<form-beans >
<form-bean name="exampleForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="age" type="java.lang.Integer" />
<form-property name="name" type="java.lang.String" />
</form-bean>
</form-beans>
validation.xml
<form-validation>
<formset>
<form name="exampleForm">
<field property="name" depends="required, minlength">
<arg0 key="exampleForm.name" />
<arg1 key="${var:minlength}" resource="false" />
<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
No comments:
Post a Comment
Note: only a member of this blog may post a comment.