Struts 2: excluding method from validation from just the defaultStack interceptor

南笙酒味 提交于 2019-12-30 10:10:45

问题


I want to be able to disable form validation for one action in Struts 2, but have the rest of the interceptor stack still be able to run.

I have an interceptor that checks to see if the user is logged in, which I always want execute, but for some actions (inputting information, for instance), I don't want the action's validate to be called.

I tried doing something like the following:

<interceptors>

    <interceptor name="bankingAuthenticator"
        class="csc309.a4.banking.BankUserAuthenticator"/>

    <interceptor-stack name="secureBanking">
        <interceptor-ref name="bankingAuthenticator"/>
        <interceptor-ref name="defaultStack"/>
    </interceptor-stack>

</interceptors>

<default-interceptor-ref name="secureBanking"/>

<action name="Deposit!*" method="{1}" class="csc309.a4.banking.Deposit">
    <result name="success">/banking/Deposit.jsp</result>
    <interceptor-ref name="defaultStack">
        <param name="workflow.excludeMethods">choose</param>
    </interceptor-ref>
</action>

But it skips out on both the bankingAuthenticator interceptor as well as the validation.


回答1:


I figured it out--the solution looks like this:

<action name="Deposit!*" method="{1}" class="csc309.a4.banking.Deposit">
    <result name="success">/banking/Deposit.jsp</result>
    <interceptor-ref name="secureBanking">
        <param name="workflow.excludeMethods">choose</param>
    </interceptor-ref>
</action>

Interceptor parameters can be restricted to specific interceptors by prepending the interceptor name to the parameter name. In this case, only the workflow interceptor will exclude the choose method; other interceptors will still fire for the choose action method.



来源:https://stackoverflow.com/questions/8116076/struts-2-excluding-method-from-validation-from-just-the-defaultstack-intercepto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!