• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Value of ActionForm in second Action that is chained

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic