• 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

Question about ActionForm in Struts

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I have a question about ActionForm. In struts-config.xml, I define my action mapping as following:


the page flow will go through init first, initiate a form instance, save it in session scope, go to InitFormAction, then forward to edit. Then..my question arised: May I change the form scope to request in edit? If I can, does it mean no form instance will be saved in session after summary.jsp?
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This type of "action chaining" is generally frowned upon. I don't know the details but I have read comments from Struts developers stating that it was never designed to handle two action on the same request. What type of processing are you doing in your init action? I would be tempted to move this into a utility class than can be shared between actions and called directly in your execute method.

- Brent
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Brent,

I too had gone through some articles that are against Action Chaining. But there scenarios in which we need to chain actions to complete a task. Let us consider a page where we create case.Once we submit we update the DB after applying business rules, we come back to a view which shows all the cases you had submitted. We can also get to this view menu from menus. This view is developed as common functionaity and as an View Action, and this goes against the db to build the view. No if i submit the case i call submit action and this updates the db, now i call the View Action to Load the views. So this kind of flow needs action chaining. I dont know is there any other better option to do it? People who are say action chaining is not good could tell the way to implement this.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is a quote from the Struts Newbie FAQ written by the Struts authors that addresses this topic:

As a rule, chaining Actions is not recommended. If your business classes are properly factored, you should be able to call whatever methods you need from any Action, without splicing them together into a cybernetic Rube Goldberg device.



For those not familiar with it, a Rube Goldberg device is clever and complicated machine that accomplishes no practical work.

I believe the important point here is elegance of code structure. The above passage is just pointing out that yes, you can chain actions, but it's not a very elegant solution.

An Action class belongs in the controller space of Model/View/Controller architecture, and as such it shouldn't contain business logic, but rather commmunicate with other objects that do contain business logic. If you find that you must use action chaining in order to make a process work, it's because you've broken this rule and put business logic in your action class.

My answer to Arulanand's challenge is that the logic to prepare for the view of a specific JSP should be placed in a Business Delegate class, rather than an Action class. Then whatever action needs to display that particular JSP should call the Business Delegate method and then forward to the JSP rather than chaining to a view action.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do the type of thing that you (Arulanand) describe all the time. I call the SaveXAction and the success forward for that action redirects to the DisplayXListAction. This does not fall into the "action chaining" category because the forward uses redirect="true". Action Chaining is an issue when you string together multiple action calls on the same request. There is a common pattern named something like "redirect after post" that describes the first scenario.

- Brent
[ November 08, 2006: Message edited by: Brent Sterling ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic