wood burning stoves 2.0*
The moose likes Struts and the fly likes Value of ActionForm in second Action that is chained Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Value of ActionForm in second Action that is chained" Watch "Value of ActionForm in second Action that is chained" New topic
Author

Value of ActionForm in second Action that is chained

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
This is the scenario using Struts:

User Interface -> Action1 (input is Form1)-> Action 2 (input is Form2) ->User Interface

Action1 and Action2 are Action classes.

Action1 and Action1 are configured in struts-config.xmxl.

Action1 takes Form1 as input.

Action2 takes Form2 as input.

Form1 and Form2 are ActionForm.

Following are the questions:

1. If Form1 and Form2 are of the same class, will Form2 get magically populated by the values obtained from Form1, when Action1 forwards to Action2?
2. Will Form2 values be empty?
3. If Form1 and Form2 are of different class, then what value will Form2 have?
4. If Form1 and Form2 are of the same class, then what value will Form2 have?
5. Is it a good idea to do Action chaining? Servlet chaining was never recommended.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
It sounds like you are talking about Struts 1.x and not about using redirect="true" for the forward to Action2. I am not an expert in this area mostly because I do not use this type of pattern because several references say that Action Chaining with Struts 1.x is not recommended.

My understanding is that when the processing for Action2 is called, it has no knowledge of Action1. The Action2 processing will go through the normal steps of creating a form instance (if needed) and populating the form with values from the request, validating your form (if needed) and calling your execute method. So for question #1) Form2 gets populated from the request, not from Form1. If you change values on Form1 during Action1 then Action2/Form2 will not see the changed values. My understanding gets real fuzzy if you talks about session scoped forms.

It helps to give real names to your examples if you are looking for help. For example if you had the two actions SaveUserProfileAction and SaveUserCreditAction that you were trying to chain together I would suggest using one action and calling separate business layer methods. If you had the two actions SaveUserProfileAction and DisplayUserSearchResultsAction (which is a very common scenario for me) then I would suggest that you redirect to the second action.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Value of ActionForm in second Action that is chained
 
Similar Threads
Passing an object between actions.
how can I make two actions communicate with each other
How to use Two Action forms into one ActionClass?
a single action a struts application
Struts forward problem