When to use Action chaining (and when not to)


The process of forwarding to another action mapping from an action is called Action Chaining. Let ‚ s say that the execute() method from an Action forwards to an ActionForward called pageB . Assume that the forward is as follows :

 <forward name=pageB path=/pageBAction.do /> 

The forward itself points to another action mapping called pageBAction . Accordingly the Action instance associated with pageBAction is invoked. This can continue until an actual JSP is shown to the user .

There are scenarios where the action chaining is a good idea. Consider the example used earlier in the chapter: A page shows a list of loans with option to delete loans one at a time. After deletion, the same loan list is shown again. If the user is forwarded directly to the List JSP after deletion, then the task of creating the loan list is left to the JSP. That is a bad design. Action chaining saves the day here. In the Action for the delete, just forward to the listLoan.do after a successful deletion. The Action corresponding to listLoan.do then creates the List of Loans to display.

Using the action mapping of self as the input attribute is a preferred than using a JSP name. This is a special case of action chaining and comes handy when a lot or preprocessing is needed to show a page, irrespective of whether page is shown for the first time in the normal way or because of validation errors.

Then there are scenarios where action chaining is a bad idea. If the chaining is used for linking several units of business logic one after the other, it is better to do this in the business tier. If this is one of your goals, then use a session ejb method as a fa ƒ §ade to hide the execution of fine-grained business logic snippets as one unit instead of chaining actions. Use the Transfer Object Assembly from the last section to create a DTO from the form bean and pass it to the business tier . Also, avoid having more than two actions in the chain. If you are having more than two actions in the chain, chances are that you are trying to do business logic by chaining Actions. A strict no-no. Nada.




Struts Survival Guide. Basics to Best Practices
Struts Survival Guide: Basics to Best Practices (J2ee Survival Series)
ISBN: 0974848808
EAN: 2147483647
Year: 2004
Pages: 96

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net