How to configure @SkipValidation by XML configuration in Struts 2

后端 未结 2 1366
庸人自扰
庸人自扰 2020-12-11 12:32

In Struts 2,

I am trying to skip validation on method base on XML configuration. As per my application I can not use annotation. So I cannot use @SkipValidati

相关标签:
2条回答
  • 2020-12-11 12:45

    You must configure validation interceptor for your action to exclude methods names that you do not want to be validated.

    <action name="..."  class="...">
      <interceptor-ref name="defaultStack">
        <param name="validation.excludeMethods">input,back,cancel,browse,delete,search,view</param>
      </interceptor-ref>
      <result>...</result>
    </action>
    
    0 讨论(0)
  • 2020-12-11 13:01

    You should configure in the struts.xml package with interceptors

    <interceptors>
      <interceptor-stack name="validateWorkflowStack">
        <interceptor-ref name="basicStack"/>
    <!-- ... whatever interceptors -->
        <interceptor-ref name="validation">
          <param name="excludeMethods">delete, search, view</param>
        </interceptor-ref>
        <interceptor-ref name="workflow"/>
      </interceptor-stack>
    </interceptors>
    

    then use action configuration

    <action name="create" class="your.package.CreateAction" method="create">
        <result name="input">/path/to/form.jsp</result>
        <interceptor-ref name="validateWorkflowStack"/>
    </action>
    

    apply interceptor to each action that has a validation interceptor referenced explicitly on action or implicitly via <default-interceptor-ref on the package.

    0 讨论(0)
提交回复
热议问题