title: How to by pass Struts validation on Cancel
body: <p>I have Struts validation interceptor mentioned in <code>struts.xml</code>.</p>
  <pre class="lang-xml prettyprint-override"><code>    &lt;!-- Configuration for the default package. --&gt;
      &lt;package name=&quot;default&quot;  extends=&quot;struts-default&quot;&gt;
          &lt;interceptors&gt;
              &lt;!-- Interceptor to handle allowing only admins to certain actions --&gt;
              &lt;interceptor name=&quot;adminOnly&quot; class=&quot;adminInterceptor&quot;/&gt;
              &lt;!-- Interceptor to handle accessDenied exceptions thrown from service/model layer called from within actions --&gt;
              &lt;interceptor name=&quot;accessDenied&quot; class=&quot;accessDeniedInterceptor&quot;/&gt;
              &lt;!-- Copied from struts-default.xml and changed validation exclude methods --&gt;
              &lt;interceptor-stack name=&quot;defaultStack&quot;&gt;
                  &lt;interceptor-ref name=&quot;accessDenied&quot;/&gt;
                  &lt;interceptor-ref name=&quot;exception&quot;/&gt;
                  &lt;interceptor-ref name=&quot;alias&quot;/&gt;
                  &lt;interceptor-ref name=&quot;servletConfig&quot;/&gt;
                  &lt;interceptor-ref name=&quot;prepare&quot;/&gt;
                  &lt;interceptor-ref name=&quot;i18n&quot;/&gt;
                  &lt;interceptor-ref name=&quot;chain&quot;/&gt;
                  &lt;interceptor-ref name=&quot;debugging&quot;/&gt;
                  &lt;interceptor-ref name=&quot;profiling&quot;/&gt;
                  &lt;interceptor-ref name=&quot;scopedModelDriven&quot;/&gt;
                  &lt;interceptor-ref name=&quot;modelDriven&quot;/&gt;
                  &lt;interceptor-ref name=&quot;fileUpload&quot;/&gt;
                  &lt;interceptor-ref name=&quot;checkbox&quot;/&gt;
                  &lt;interceptor-ref name=&quot;staticParams&quot;/&gt;
                  &lt;interceptor-ref name=&quot;params&quot;&gt;
                      &lt;param name=&quot;excludeParams&quot;&gt;dojo\..*&lt;/param&gt;
                  &lt;/interceptor-ref&gt;
                  &lt;interceptor-ref name=&quot;conversionError&quot;/&gt;
                  &lt;interceptor-ref name=&quot;validation&quot;&gt;
                      &lt;param name=&quot;excludeMethods&quot;&gt;cancel,execute,delete,edit,list&lt;/param&gt;
                  &lt;/interceptor-ref&gt;
                  &lt;interceptor-ref name=&quot;workflow&quot;&gt;
                      &lt;param name=&quot;excludeMethods&quot;&gt;input,back,browse,cancel&lt;/param&gt;
                  &lt;/interceptor-ref&gt;
              &lt;/interceptor-stack&gt;
              &lt;interceptor-stack name=&quot;fileUploadStack&quot;&gt;
                  &lt;interceptor-ref name=&quot;fileUpload&quot;/&gt;
                  &lt;interceptor-ref name=&quot;defaultStack&quot;/&gt;
              &lt;/interceptor-stack&gt;
              &lt;interceptor-stack name=&quot;adminCheck&quot;&gt;
                  &lt;interceptor-ref name=&quot;defaultStack&quot;/&gt;
                  &lt;interceptor-ref name=&quot;adminOnly&quot;/&gt;
              &lt;/interceptor-stack&gt;
          &lt;/interceptors&gt;
  
  
  
  &lt;action name=&quot;editUser&quot; class=&quot;userAction&quot; method=&quot;edit&quot;&gt;
              &lt;interceptor-ref name=&quot;adminCheck&quot;/&gt;
              &lt;result name=&quot;success&quot;&gt;/WEB-INF/pages/userForm.jsp&lt;/result&gt;
              &lt;result name=&quot;input&quot;&gt;/WEB-INF/pages/admin/userList.jsp&lt;/result&gt;
              
          &lt;/action&gt;
          
           &lt;action name=&quot;cancelUser&quot; class=&quot;userAction&quot; method=&quot;cancel&quot;&gt;     
           
           &lt;result name=&quot;cancel&quot; type=&quot;redirectAction&quot;&gt;admin/users&lt;/result&gt;      
           &lt;!--    &lt;result name=&quot;cancel&quot;&gt;/WEB-INF/pages/admin/userList.jsp&lt;/result&gt; --&gt;          
           &lt;/action&gt;
  
  &lt;action name=&quot;saveUser&quot; class=&quot;userAction&quot; method=&quot;save&quot;&gt;
           &lt;!--    &lt;result name=&quot;cancel&quot; type=&quot;redirectAction&quot;&gt;admin/users&lt;/result&gt;  --&gt;
              &lt;result name=&quot;input&quot;&gt;/WEB-INF/pages/userForm.jsp&lt;/result&gt;
              &lt;result name=&quot;success&quot; type=&quot;redirectAction&quot;&gt;admin/users&lt;/result&gt;
          &lt;/action&gt;
  </code></pre>
  <p>And then I have JSP page in which I mention</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;s:form name=&quot;userForm&quot; action=&quot;saveUser&quot; method=&quot;post&quot; validate=&quot;true&quot; cssClass=&quot;well&quot; autocomplete=&quot;off&quot;&gt;   
  </code></pre>
  <p>And form has 3 submit buttons.</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;div id=&quot;actions&quot; class=&quot;form-group&quot;&gt;
              &lt;s:submit type=&quot;button&quot; cssClass=&quot;btn btn-primary&quot; method=&quot;save&quot; key=&quot;button.save&quot; theme=&quot;simple&quot;&gt;
                  &lt;i class=&quot;icon-ok icon-white&quot;&gt;&lt;/i&gt;
                  &lt;fmt:message key=&quot;button.save&quot;/&gt;
              &lt;/s:submit&gt;
              &lt;c:if test=&quot;${param.from == 'list' and not empty user.id}&quot;&gt;
                  &lt;s:submit type=&quot;button&quot; cssClass=&quot;btn btn-danger&quot; method=&quot;delete&quot; key=&quot;button.delete&quot;
                            onclick=&quot;return confirmMessage(msgDelConfirm)&quot; theme=&quot;simple&quot;&gt;
                      &lt;i class=&quot;icon-trash&quot;&gt;&lt;/i&gt;
                      &lt;fmt:message key=&quot;button.delete&quot;/&gt;
                  &lt;/s:submit&gt;
              &lt;/c:if&gt;
              &lt;s:submit type=&quot;button&quot; cssClass=&quot;btn btn-default&quot; method=&quot;cancel&quot; action=&quot;cancelUser&quot;  key=&quot;button.cancel&quot; theme=&quot;simple&quot;&gt;
                  &lt;i class=&quot;icon-remove&quot;&gt;&lt;/i&gt;
                  &lt;fmt:message key=&quot;button.cancel&quot;/&gt;
              &lt;/s:submit&gt;
          &lt;/div&gt;
          &lt;/s:form&gt;
  </code></pre>
  <p>And my action class has these methods :</p>
  
  <pre><code>public String execute() {
      return SUCCESS;
  }
  
  
  public String cancel() {
      if (!&quot;list&quot;.equals(from)) {
          return &quot;home&quot;;
      }
      return &quot;cancel&quot;;
  }
  
  
  public String save() throws Exception {
  
      Integer originalVersion = user.getVersion();
  
      boolean isNew = (&quot;&quot;.equals(getRequest().getParameter(&quot;user.version&quot;)));
      // only attempt to change roles if user is admin
      // for other users, prepare() method will handle populating
      if (getRequest().isUserInRole(Constants.ADMIN_ROLE)) {
          user.getRoles().clear(); // APF-788: Removing roles from user
                                      // doesn't work
          String[] userRoles = getRequest().getParameterValues(&quot;userRoles&quot;);
  
          for (int i = 0; userRoles != null &amp;&amp; i &lt; userRoles.length; i++) {
              String roleName = userRoles[i];
              try {
                  user.addRole(roleManager.getRole(roleName));
              } catch (DataIntegrityViolationException e) {
                  return showUserExistsException(originalVersion);
              }
          }
      
  </code></pre>
  <p>Validations are getting triggered on click of Cancel button too. Is there a way to stop validations from getting triggered on click of Cancel?</p>
  <p><strong>Changed code :</strong></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;!-- Configuration for the default package. --&gt;
      &lt;package name=&quot;default&quot;  extends=&quot;struts-default&quot;&gt;
          &lt;interceptors&gt;
              &lt;!-- Interceptor to handle allowing only admins to certain actions --&gt;
              &lt;interceptor name=&quot;adminOnly&quot; class=&quot;adminInterceptor&quot;/&gt;
              &lt;!-- Interceptor to handle accessDenied exceptions thrown from service/model layer called from within actions --&gt;
              &lt;interceptor name=&quot;accessDenied&quot; class=&quot;accessDeniedInterceptor&quot;/&gt;
              &lt;!-- Copied from struts-default.xml and changed validation exclude methods --&gt;
              &lt;interceptor-stack name=&quot;myDefaultStack&quot;&gt;
                  &lt;interceptor-ref name=&quot;accessDenied&quot;/&gt;
                  &lt;interceptor-ref name=&quot;exception&quot;/&gt;
                  &lt;interceptor-ref name=&quot;alias&quot;/&gt;
                  &lt;interceptor-ref name=&quot;servletConfig&quot;/&gt;
                  &lt;interceptor-ref name=&quot;prepare&quot;/&gt;
                  &lt;interceptor-ref name=&quot;i18n&quot;/&gt;
                  &lt;interceptor-ref name=&quot;chain&quot;/&gt;
                  &lt;interceptor-ref name=&quot;debugging&quot;/&gt;
                  &lt;interceptor-ref name=&quot;profiling&quot;/&gt;
                  &lt;interceptor-ref name=&quot;scopedModelDriven&quot;/&gt;
                  &lt;interceptor-ref name=&quot;modelDriven&quot;/&gt;
                  &lt;interceptor-ref name=&quot;fileUpload&quot;/&gt;
                  &lt;interceptor-ref name=&quot;checkbox&quot;/&gt;
                  &lt;interceptor-ref name=&quot;staticParams&quot;/&gt;
                  &lt;interceptor-ref name=&quot;params&quot;&gt;
                      &lt;param name=&quot;excludeParams&quot;&gt;dojo\..*&lt;/param&gt;
                  &lt;/interceptor-ref&gt;
                  &lt;interceptor-ref name=&quot;conversionError&quot;/&gt;
                  &lt;interceptor-ref name=&quot;validation&quot;&gt;
                      &lt;param name=&quot;excludeMethods&quot;&gt;cancel,execute,delete,edit,list&lt;/param&gt;
                  &lt;/interceptor-ref&gt;
                  &lt;interceptor-ref name=&quot;workflow&quot;&gt;
                      &lt;param name=&quot;excludeMethods&quot;&gt;input, back, browse, cancel&lt;/param&gt;
                  &lt;/interceptor-ref&gt;
              &lt;/interceptor-stack&gt;
              &lt;interceptor-stack name=&quot;fileUploadStack&quot;&gt;
                  &lt;interceptor-ref name=&quot;fileUpload&quot;/&gt;
                  &lt;interceptor-ref name=&quot;myDefaultStack&quot;/&gt;
              &lt;/interceptor-stack&gt;
              
            &lt;!--   &lt;default-interceptor-ref name=&quot;myDefaultStack&quot;/&gt; --&gt;
            
              &lt;interceptor-stack name=&quot;adminCheck&quot;&gt;
                  &lt;interceptor-ref name=&quot;myDefaultStack&quot;/&gt;
                  &lt;interceptor-ref name=&quot;adminOnly&quot;/&gt;
              &lt;/interceptor-stack&gt;                      
          &lt;/interceptors&gt;
              
              
           &lt;default-interceptor-ref name=&quot;myDefaultStack&quot;/&gt;
  </code></pre>