File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes action chaining Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "action chaining" Watch "action chaining" New topic
Author

action chaining

Pranav Sharma
Ranch Hand

Joined: Oct 27, 2003
Posts: 258
hi
I have a situation where I have to merge work between different developers of a struts enabled web-app.
Every jsp has 2 actions. Like:
OUTPUT ACTION1 ----> JSP1 -----> INPUT ACTION1

OUTPUT ACTION2 ----> JSP2 -----> INPUT ACTION2

The output action is used to populate the jsp fields. and the Input Action to persist the data.

Now to merge 1 and 2. I know I can

forward INPUT ACTION1 to OUTPUT ACTION2 and I understand this is action chaining.
However I read online that action chaining is not recommended.

My Questions:
1) If the above is an acceptable solution
2) Why is it not recommended to do action chaining

Thanks
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

It's true that Action chaining is not recommended but your scenario is an exception. The "output" Actions you refer to are often called Setup or Populate actions.

As far as I'm concerned, this is a best practice when using Struts

Craig McClanahan's talk on JSF refers to this Struts practice as bad but blames the framework rather than the practice.
[ August 02, 2005: Message edited by: Marc Peabody ]

A good workman is known by his tools.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727


[ August 02, 2005: Message edited by: Marc Peabody ]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Chaining actions is certainly possible, and the solution you propose would work.

The objections to chaining actions have more to do with programming style than anything else. The reason most authors object to it is that it indicates your code may not be structured in the best way to follow the MVC model.

In the Struts framework, the Action class is 100% controller. This means that it's job is to coordinate between the view and the model. As such, it shouldn't have model logic or view logic contained in it. If a page requests information that must be obtained from a database, the action form should call on a model object to perform that database access rather than doing it within the action class.

Where I'm going with this is that if you have to do action chaining to make your application work, you probably have too much model logic in your action class.

To use your example, most of the what Output Action 2 does to get it's data should be contained in a model object. Therefore, it should be fairly easy for Input Action 1 to call the same method on the model object that Output Action 2 does. You could thereby eliminate Output Action 2 altogether.


Merrill
Consultant, Sima Solutions
Pranav Sharma
Ranch Hand

Joined: Oct 27, 2003
Posts: 258
thanks guys.

Merrill, the web app actually is structured pretty well, with model objects implementing majority of the population behavior. However my problem is with logistics, cause we have two teams in California and Maryland.
I did not want to mess with the actions written by the other team and so the chaining.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: action chaining