aspose file tools*
The moose likes Struts and the fly likes ValidatorActionForm Question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ValidatorActionForm Question?" Watch "ValidatorActionForm Question?" New topic
Author

ValidatorActionForm Question?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9349
    
    2

What is the use of ValidatorActionForm and DynaValidatorActionForm? Can anyone give me just a brief explanation?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9349
    
    2

Any help guys?
Nick Williamson
Ranch Hand

Joined: Jan 06, 2007
Posts: 73
rtfm

http://struts.apache.org/1.3.8/faqs/validator.html
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9349
    
    2

I'm actually using Struts 1.2.9, so found a tutorial for that version. Anyways, thanks for the link!
Nick Williamson
Ranch Hand

Joined: Jan 06, 2007
Posts: 73
Ok good, I don't think there's much of a difference with validation between the two versions. I think the jump was between 1.x and 2.x, Either way you go to the struts website and there's plenty of documentation there.
ngpgeeta
Greenhorn

Joined: Feb 11, 2007
Posts: 1
In addition to the two standard options for creating Form Beans(validatorForm or DynaValidatorForm), 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:

<form-bean name="addressForm" type="org.apache.struts .validator.DynaValidatorActionForm"> ... </form-bean>

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:

<action-mappings> <action path="/technology/createAddress" type="com.jamesholmes .minihr.CreateAddressAction" name="addressForm"/> <action path="/technology/editAddress" type="com.jamesholmes .minihr.EditAddressAction" name="addressForm"/> </action-mappings>

Hope this helps
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9349
    
    2

Hey geeta,

Thanks for the post!
Emi Garcia
Greenhorn

Joined: Nov 02, 2010
Posts: 16
ngpgeeta wrote:In addition to the two standard options for creating Form Beans(validatorForm or DynaValidatorForm), 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:

<form-bean name="addressForm" type="org.apache.struts .validator.DynaValidatorActionForm"> ... </form-bean>

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:

<action-mappings> <action path="/technology/createAddress" type="com.jamesholmes .minihr.CreateAddressAction" name="addressForm"/> <action path="/technology/editAddress" type="com.jamesholmes .minihr.EditAddressAction" name="addressForm"/> </action-mappings>

Hope this helps



i know the post is old.

but i have a question very very related!

so:

if i have 1 formBean and many actions like add and edit i do that.

but what happens if i have 1 formBean and 1 Action that extendes org.apache.struts.actions.DispatchAction so i can have diferent methods for different use, but i still want to use the validator framework?

is there any way to map each validation type with each method or i have to code many actions?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ValidatorActionForm Question?