*
The moose likes Struts and the fly likes How to dynamically set the value of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to dynamically set the value of "input" in  Dispatch Action for Struts Validation" Watch "How to dynamically set the value of "input" in  Dispatch Action for Struts Validation" New topic
Author

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

Solo Chiang
Greenhorn

Joined: Sep 14, 2005
Posts: 18
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

Joined: Feb 05, 2003
Posts: 4727

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");
}


A good workman is known by his tools.
Shailesh Kumar Saxena
Greenhorn

Joined: Dec 15, 2012
Posts: 25

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">.....


Shailesh Saxena,
Pilibhit, U.P. INDIA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to dynamically set the value of "input" in Dispatch Action for Struts Validation
 
Similar Threads
Redirecting to the JSP when validation error occurs
LookupDispatch action with validator
Validations using ActionErros Validate
Validation Problem
XML Validation in struts