File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ValidatorActionForm Question?

 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the use of ValidatorActionForm and DynaValidatorActionForm? Can anyone give me just a brief explanation?
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any help guys?
 
Nick Williamson
Ranch Hand
Posts: 73
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm actually using Struts 1.2.9, so found a tutorial for that version. Anyways, thanks for the link!
 
Nick Williamson
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey geeta,

Thanks for the post!
 
Emi Garcia
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic