struts2 resultType为chain时 传值

应用场景:

  a页面保单提交进行validation验证,如果验证不通过则跳转到当前页面并展现已有数据列表,也就是a页面既包含新增表单,又有列表展现。

  一开始的想法是用redirect 类型,可以这个类型明显不行,拿不到验证不通过的信息。

 后来决定用chain,但是跳转是跳转过来,可没有去走chain跳转到action中的方法

如下列代码:aAction验证不通过,chain到bList,(备注 :1,两个在同一个namespace,2,bList result为input类型的一定要配置)

但是却没有走listB这个方法,而是直接把验证错误信息展现到b_list.jsp。显然结果不对。 

<action name="aAction" class="com.AAction" method="detailA">
            <result name="success" type="redirect">AList.html?id=${id}</result>
            <result name="input" type="chain">bList</result>
</action>

<action name="bList" class="com.BAction" method="listB">
            <result name="success" type="dispatcher">b_list.jsp</result>
            <result name="input" type="dispatcher">b_list.jsp</result>
</action>
 

解决方法:

<action name="bList" class="com.BAction" method="listB">
            <result name="success" type="dispatcher">b_list.jsp</result>
            <result name="input" type="dispatcher">b_list.jsp</result>
            <interceptor-ref name="default-stack">
                <param name="workflow.excludeMethods">bList</param>
            </interceptor-ref>
</action>

加上这段配置,就可以执行方法后并且一起把错误信息输出到页面。

 

补充文章:http://psjay.com/struts2-validate-chain-important-point.html

 

 

posted @ 2012-07-07 23:45  _zao123  阅读(1229)  评论(0编辑  收藏  举报