File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to dynamically set the value of "input" in Dispatch Action for Struts Validation

 
Solo Chiang
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all

Does anyone have experience on performing Struts Validation which covers multiple methods by using DispatchAction? How do you specified the input value for each method in the dispatch action?

For example, I have a action called UserProfileAdmin, which contains 3 methods, edit user, create user, delete user. For each method it is supposed to have different value set in the attribute "input" because validation need it.

But when you use DispatchAction and defined all 3 methods in one action mapping in struts-config.xml, it allowes us to have only one "input" attribute in this action mapping definition.

In that case, no matter the validation fails in either "edit user", "create user" or "edit user", it could only forwared to a single target, which is bad...

Please help me if you know how to resolve this, thanks a lot!
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set it to validate="false".
You can manually call the validate method from DispatchAction's methods.
It will look something like this:

errors.add(form.validate());
if(!errors.isEmpty()){
saveErrors(request, mapping);
return mapping.findForward("updateFailure");
}
 
Shailesh Kumar Saxena
Greenhorn
Posts: 25
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though this post is already dead being too old. But still I wanna put more appropriate answer for it.

for your 3 methods editUser(----), createUser(----) and deleteUser(----) configure your DispatchAction class 3 times in struts-config.xml with same type="" value and if you are also using single common ActionForm(form bean) class take same values for name="" in all 3 configurations. just change the input="" values according to your need.(But put 3 different action="" values in each config.)
And in validation.xml file tale <form name="action value used by particular form page to transfer control to DipatchAction class">.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic