• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Action Chaining and request paramters

 
Manish Hatwalne
Ranch Hand
Posts: 2595
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic