Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

WebWork provides the ability to chain multiple actions into a defined sequence or workflow. This feature works by applying a Chain Result to a given action, and intercepting its target action's invocation with a ChainingInterceptor.

Chain Result

The Chain Result is a result type that invokes an action with its own interceptor stack and result. This allows an action to forward requests to a target action, while propagating the state of the source action. Below is a simple example of how to define this sequence.

Code Block
xml
xml
<!-- 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 action in the same namespace (or the default "" namespace) can be executed after this Action action (see Configuration). An optional "namespace" parameter may also be added to specify an Action action in a different namespace.

Chaining Interceptor

If you need to copy the properties from your previous Actions in the chain to the current action, you should apply the ChainingInterceptor. The interceptor will copy the original parameters from the request, and the ValueStack are is 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 the target action. The source action is remembered by the ValueStack, allowing the target action to access the properties of the preceding Actionaction(s) using the ValueStack, and also makes these properties available to the final result of the chain, such as the JSP or Velocity page.

Chaining Interceptor

However, this is only half of the equation. In order for the chain result to

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

One common use of Action action chaining is to provide lookup lists (like for a dropdown list of states, etc). Since these Actions 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 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 ActionYou may also use the Redirect Action Result to accomplish this.