JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > WebWork > Action Chaining
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  Action Chaining
Added by scud, last edited by scud on Apr 30, 2006  (view change)
Labels: 
(None)

Overview

WebWork提供把多个Action按照预先定义好的顺序或者流程链接起来的能力.这个特性通过给指定的Actions设置一个Chain Result,然后通过一个ChainingInterceptor 拦截目标Action来实现.

警告

通常不推荐使用Action链.但是,你可以有其他选择,例如redirect after post技术

Chain Result

Chain Result是一种result 类型,它基于自己的拦截器stack(堆栈)和result调用一个action,这样允许一个action附带着原来的状态将请求转到目标action,下面是关于如何定义这样的一个序列的例子.

Content pulled from external source. Click here to refresh.
<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>

在这个Action(参见 配置文件)执行之后同一命名空间(或者是默认的""命名空间)的另外一个Action也会得到执行.一个可选的"namespace"参数来指定另外一个命名空间的Action

Chaining Interceptor

如果你需要把Action链中早先的Actions的属性复制到当前的Action中,你应该采用ChainingInterceptor. 这个拦截器会从request和ValueStack中复制所有的原始参数传给目标Action. ValueStack会记录Action源的信息,这样目标Action就可以通过ValueStack访问早先的Action的属性,这些属性也能被Action链中最后的result访问,例如JSP或者Velocity页面.

Action链通常用来提供查找列表(例如状态的下拉列表等等).既然这些Actions已经放入了ValueStack,它们的属性在View层就是可用的.这个功能也可以使用Action标签(ActionTag)在显示页面执行一个Action来做到.你也可以利用Redirect Action Result来完成这样的功能.

Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators