struts2interceptorinterceptorstack

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


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.


Solution

  • 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.