An action encapsulates a piece of functionality; e.g., you might have a login action or a sign address book action. Over time as you build projects with actions, you see common functionality that you would like to abstract out to make reusable. What you would like to do is describe a discrete piece of functionality and reuse it across applications.
So, lets think of an action as a link in a chain. It may be the first link, last link, or a link in the middle. The ordering of this link should be abstracted but the functionality of the link should be the same. This chaining of actions is supported in WW.
Lets take a simple example of an action (Foo) where its sole purpose is to capitalize a title. This action provides a setter for a title and its execute() method capitalizes the title. Next, lets say you have an action (Bar) that provides a setter for title and does nothing.
Now, you want to chain together these two actions to perform some work. So, you build a chain in the view map, see below.
# action chaining actionchain.foo.action=Foo actionchain.foo.success=actionchain.bar.action actionchain.bar.action=Bar actionchain.bar.success=bar.jsp ## Need an input view because I am explicitly add an error from the execution of Foo. ## The error will be propogated to Bar so Bar will need to handle it which will require ## an input or error view actionchain.bar.input=bar.jsp
Now, that your chain is built you are ready to go. So, lets take for instance a form that posts to actionchain.foo.action. WW will set all parameters on Foo and call its execute(). Upon a successful return, WW finds that the result is an action and not a view so it finds this action, loads it, sets its context which includes copying appropriate attributes from the previous action, and finally calling Bar's execute() method. If Bar returns a view, then WW will forward the request to this view.
Now, lets take a little deeper look. First, lets assume that both Foo and Bar extend ActionSupport. Then, assume Foo adds an error in its execution. When Foo's attributes are copied to Bar the errors will be copied as well. This means when Bar is executed, ActionSupport will return an INPUT view. Note, this means that Bar will not have its doExecute() called. WW will then search the map for an INPUT view and forward the request to this view.
This example only demonstrated a two link chain. The limit to your chain is set via WW's property 'webwork.action.chain.maxlinks' which is set to 10 by default.