Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

java - How to configure @SkipValidation by XML configuration in Struts 2

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 @SkipValidation annotation. Is there any alternative for this?

I have one action class which has five methods create, update, delete, search, and view. I want to validate only two methods create and update.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...