Dashboard > WebWork > ... > Reference > Action Chaining
  WebWork Log In View a printable version of the current page.  
  Action Chaining
Added by Jason Carreira, last edited by Philip Luppens on Mar 21, 2006  (view change)
Labels: 
(None)

Overview

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.

Warning

In general, Action Chaining is not recommended. However, there are other options, such as the redirect after post technique.

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 an example of how to define this sequence.

<package name="public" extends="webwork-default">
    <!-- Chain creatAccount to login, using the default parameter -->
    <action name="createAccount" class="...">
        <result type="chain">login</result>
    </action>

    <action name="login" class="...">
        <!-- Chain to another namespace -->
        <result type="chain">
            <param name="actionName">dashboard</param>
            <param name="namespace">/secure</param>
        </result>
    </action>
</package>

<package name="secure" extends="webwork-default" namespace="/secure">
    <action name="dashboard" class="...">
        <result>dashboard.jsp</result>
    </action>
</package>

Another action in the same namespace (or the default "" namespace) can be executed after this action (see Configuration Files). An optional "namespace" parameter may also be added to specify an 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 is passed in to the target action. The source action is remembered by the ValueStack, allowing the target 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.

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. You may also use the Redirect Action Result to accomplish this.

One interesting fact I've found is that since 2.2 DefaultWorkflowInterceptor (aliased as "workflow") is included in defaultStack. So if first action in the chain adds action errors, execution will be redirected to the "input" result of the second action, skipping second action itself.

I've spend an hour before understood this. Maybe this note should be included in page itself...

Posted by Stepan Koltsov at Nov 01, 2005 10:40 | Permalink
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators