aspose file tools*
The moose likes Struts and the fly likes Action Chaining and request paramters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Action Chaining and request paramters" Watch "Action Chaining and request paramters" New topic
Author

Action Chaining and request paramters

Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

I have a little complicated problem, but I'll try to simplify it to exlain what I am doing.

For some complicated reasons, I need to do Action Chaining (I know this is not recommended generally, but I must do it because some complicated work has been delegated to one generic action).

So, in a simplified version this is what it is --

I have two actions - action "A" and action "B", out of which action A is generic action and need to be used by many forms/pages. Now my form posts 2 parameters, say "X" and "Y" to action A. action A processes only parameter "X" and forwards it to action "B" -- which is supposed to process parameter "Y". However, this parameter "Y" is not available to action "B" after this forward, and I wonder what can I do to get thsi working.

My configuration correctly has this forward configured as "redirect=false"

<action path="/A" type="com.circussoftware.struts.ActionA"
name="abcForm" scope="request" input="/abc.vm">
<forward name="goHere" path="/B.do" redirect="false"/>
</action>

What can I do here?? We do need to have action "A" pretty generic, so action chaing is must for making it work for various purposes. How can I allow action B to access parameter Y??? Is there any configuration parameter that I can twist and make this work?? I am using Tomcat 5 as my container.

TIA,
- Manish
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
hmmm...if you are not redirecting then the execution of both actions should occur on the same request so it sure seems like all values submitted from the page should still be available on the request. Are you sure that "Y" is being submitted and that it is not available in Action "B"?

I have seen it mentioned on the Struts Developer mailing list that the Struts internals do not handle action chaining very well. I do not know what the specific issues are though.

- Brent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When action chaining, you must re-send the parameters in the URL to the next action.

So, in order for Action A to forward parameters to action B, you must not use mapping.findForward(), but create a forward dynamically something like this:

return new ActionForward("/B.do?X="+x+"&Y="+y", false);
[ May 31, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Really? Even when the forward does not redirect? I would have thought that both actions would have seen the same request object, but action chaining (without redirecting) is something that I avoid...mostly just so the URL in the browser is updated.

BTW, here is a utility method that I put together to add a parameter to an ActionForward. It might be a bit of overkill, but I like defining the forwards in struts-config.


- Brent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I know, Brent, it seems odd, but this is what seems to work. Anything put in the request using the setAttribute method will get passed, but parameters have to be repackaged and passed again.

Like you, I avoid action chaining. Action chaining is usually an indication that one is putting too much business logic in the Action class as opposed to business delegates and model classes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Action Chaining and request paramters
 
Similar Threads
any idea please
InvocationTargetException.
simple question about formbean
Struts Cancel Button submits the form
DispatchAction coding problem ~~mod pls check this thread, display problem,tq