What's the difference between ValidatorForm and ValidatorActionForm?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   michael_mingking
Posted On:   Wednesday, August 11, 2004 12:14 AM

What's the difference between ValidatorForm and ValidatorActionForm?
Which one should I use? any advice to choose between them?
how about DynaActionForm DynaValidatorActionForm and DynaValidatorForm ?

thanks in advance!!!

Re: What's the difference between ValidatorForm and ValidatorActionForm?

Posted By:   Fernando_Sanabria  
Posted On:   Wednesday, August 18, 2004 10:38 AM

I hope this explanation answers your doubt:

In addition to the two standard options for creating Form Beans, Validator provides an advanced feature for tying multiple validation definitions to one Form Bean definition. When you use validatorForm- or DynaValidatorForm-based Form Beans, Validator uses the logical name for the Form Bean from the struts-config.xml file to map the Form Bean to validation definitions in the validation.xml file. This mechanism is great in most cases, but in some scenarios, Form Beans are shared among multiple actions. One action may use all of the Form Bean's fields, and another action may use only a subset of the fields. Because validation definitions are tied to the Form Bean, the action that uses only a subset of the fields has no way of bypassing validations for the unused fields. When the Form Bean is validated, it generates error messages for the unused fields, because Validator has no way of knowing not to validate the unused fields; it simply sees them as missing or invalid.



To solve this problem, Validator provides two additional ActionForm subclasses that allow you to tie validations to actions instead of to Form Beans. That way you can specify which validations to apply to the Form Bean based on which action is using the Form Bean. For concrete Form Beans, you subclass org.apache.struts.validator.ValidatorActionForm, as follows:





public class AddressForm extends ValidatorActionForm {
...
}




For dynamic Form Beans, you specify a type of org.apache.struts.validator.DynaValidatorActionForm for your Form Bean definition in the struts-config.xml file, as follows:




type="org.apache.struts
.validator.DynaValidatorActionForm">
...




Inside your validation.xml file, you map a set of validations to an action path instead of to a Form Bean name, because if you have two actions defined, Create Address and Edit Address, which use the same Form Bean, each will have a unique action path, as follows:





type="com.jamesholmes
.minihr.CreateAddressAction"
name="addressForm"/>
type="com.jamesholmes
.minihr.EditAddressAction"
name="addressForm"/>



Regards,

FerSan
About | Sitemap | Contact