A recent thread here touched upon the 'hazards' of chaining Actions. While there has been debate in various forums over good vs. bad chaining I'm not quite sure of what is meant by chaining actions. Depending on the source, it would appear to me that actionA is considered chained to ActionB if any of the following apply: a) the operation started by ActionA is incomplete unless followed by ActionB. b) ActionB can not succeed unless preceeded by ActionA. c) ActionA simply fowards to /ActionB.do (regardless of the redirect option) d) ActionA forwards to /ActionB.do without a redirect (with redirect is ok) e) ActionA builds the ActionForward to ActionB on the fly. Is there a more rigorous definition? Is the above accurate? Complete? My first reaction to the NEVER CHAIN ACTIONS statements was that somebody is recommending that all Actions forward only to JSPs? Upon further reading I think that the intent of that statement is to discourage having Actions figure out or be dependent upon a specific flow. The recommended approach is to reuse very specific Actions in multiple mappings and let the mapping dictate the forwards. The Actions themselves are dumb as to the flow. But even in this recommended approach, don't we still end up with an action chain?
Rich I'm posting this to figure out what I know and to hear from others who have wisdom to share on this topic. Rich
I'm being lazy today (and I'm also at work and stealing in posts, as usual) so it would be great if somebody would care to expound on the Cons of chaining actions. In my limited experience with Struts, chaining is not all that harmful if done in moderation and in good taste I see Action chaining as similar to Filter chaining. Also, if you see one Action beginning to have too much of a dependency on another upstream (or upchain as it may be) Action, shouldn't this be taken as a sign that some refactoring is in order?
Also, if you see one Action beginning to have too much of a dependency on another upstream (or upchain as it may be) Action, shouldn't this be taken as a sign that some refactoring is in order?
Yes. Then again it's not hard to agree Clearly using action chaining (and I used the term without having a clear definiton - see original post) is ok in the context of say, dispath type actions, where the very design suggests that the dispatch action can be chained to another Action. And clearly action chaining is bad in situation where it introduces errors, such as when action1 sets a property that is subsequently lost when the request is forwarded to action2, which shares the same ActionForm. In between these extremes there are the situations where you determine how the chaining contrains the reuse of your actions and then act accordingly. If all there was to this issue was "use your common sense" then there would be no issue at all. So what am I missing? Rich