You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

The ActionChainResult in WebWork2 provides the ability to compose multiple Actions together to execute in a defined sequence or workflow. By applying the ActionChainResult as the result of your Action, like so:

<!-- simple chain example to an action in same namespace ->
<result name="success" type="chain">
    <param name="actionName">Bar</param>
</result>
<!- example of chaining to an action in a different namespace/package -->
<result name="success" type="chain">
	<param name="actionName">viewFoo</param>
	<param name="namespace">/foo</param>
</result>	

another Action in the same namespace (or the default "" namespace) can be executed after this Action (see XWork Configuration). An optional "namespace" parameter may also be added to specify an Action in a different namespace. The original parameters from the request and the ValueStack are passed in when this Action is chained to, so the chained to Action will be added on the ValueStack above the chained from Action. This allows the chained to Action to access the properties of the preceding Action(s) using the ValueStack, and also makes these properties available to the final result of the chain, such as the JSP or Velocity page.

If you need to copy the properties from your previous Actions in the chain to the current Action, you should apply the ChainingInterceptor (see XWork Interceptors) which copies the properties of all objects on the ValueStack to the current target.

One common use of Action chaining is to provide lookup lists (like for a dropdown list of states, etc). Since these Actions get put on the ValueStack, these properties will be available in the view. This functionality can also be done using the ActionTag to execute an Action from the display page. In WW1.x Action chaining is often used to chain to a RedirectAction to redirect to another page after processing (in WW2 we have a redirect result).

Basically it's good when you have some reusable code you want to encapsulate... In WW2 if you use it a lot, you could make it an Interceptor, or use it as an Action with chaining. If you need to set up and use some properties from it, it needs to be an Action.

  • No labels