title: Struts 2 validate method not working without XML
body: <p>I'm using Struts 2 for developing a web application. I have action class implementing <code>ActionSupport</code>. My problem is that when I enter some text error messages are not getting cleared as well as form is also not getting submitted.</p>
  <p>Here's what I have:</p>
  <p><strong><code>CustomerAction.java</code>:</strong></p>
  <pre><code>public class CustomerAction extends ActionSupport
      {
      private Customer customer = new Customer();
      
      private String customerName;
      
      private String emailID;
      
      public String getCustomerName() {
              return customerName;
          }
      
          public void setCustomerName(String customerName) {
              this.customerName = customerName;
          }
      public Customer getCustomer() {
              return customer;
          }
      
          /**
           * @param customer
           */
          public void setCustomer(Customer customer) {
              this.customer = customer;
          }
      
      public String getEmailID() {
              return emailID;
          }
      
          public void setEmailID(String emailID) {
              this.emailID = emailID;
          }
      
      public void validate()
          {
              
              if (customerName == null)
              {
                  
                  addFieldError(&quot;customer.customerName&quot;,&quot;Required&quot;);
                  
              }
      
              if (emailID == null || emailID.trim().equals(&quot;&quot;))
              {
                  addFieldError(&quot;customer.emailID&quot;,&quot;Email is Required&quot;);
                  }
  
          }
  </code></pre>
  <p><strong><code>Struts.xml</code>:</strong></p>
  <pre><code>    &lt;action name=&quot;addCustomer&quot; class=&quot;com.yell.hibu.action.CustomerAction&quot; method=&quot;execute&quot;&gt;
      &lt;interceptor-ref name=&quot;params&quot;&gt;
      
      &lt;param name=&quot;excludeParams&quot;&gt;dojo\..*,^struts\..*&lt;/param&gt;
      
      &lt;/interceptor-ref&gt;
      
      &lt;interceptor-ref name=&quot;validation&quot;&gt;
      
      &lt;param name=&quot;excludeMethods&quot;&gt;input,back,cancel,browse&lt;/param&gt;&lt;/interceptor-ref&gt;
      
      &lt;interceptor-ref name=&quot;workflow&quot;&gt;
      
      &lt;param name=&quot;excludeMethods&quot;&gt;input,back,cancel,browse&lt;/param&gt;
      
     &lt;/interceptor-ref&gt;
    &lt;result name=&quot;input&quot;&gt;/registration.jsp&lt;/result&gt;
   &lt;result name=&quot;success&quot;&gt;/success.jsp&lt;/result&gt;
  &lt;/action&gt;
  &lt;/package&gt;
  &lt;/struts&gt;
  </code></pre>
  <p><strong><code>regisration.jsp</code>:</strong></p>
  <pre><code>    &lt;%@ taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot;%&gt;
      
      &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
     
  
   
  &lt;html&gt;
  &lt;head&gt;
  
   &lt;title&gt;Customer Registration Form&lt;/title&gt;
    &lt;s:head/&gt;
   &lt;/head&gt;
  &lt;body&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;center&gt;
  &lt;table width=&quot;450&quot; align=&quot;center&quot;&gt;
              &lt;tr&gt;
  &lt;td align=&quot;center&quot; height=&quot;40&quot;&gt;&lt;font
  style=&quot;color: #003300; font-family: fantasy !important;&quot;&gt;&lt;strong
                          style=&quot;color: #003300 !important;&quot;&gt;Registration Form&lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td width=&quot;1000&quot; align=&quot;center&quot;&gt;&lt;br&gt; &lt;font color=&quot;#003300&quot;&gt;&lt;s:actionerror/&gt;
  &lt;s:form action=&quot;addCustomer&quot; id=&quot;register-form&quot; method=&quot;post&quot; theme=&quot;xhtml&quot; enctype=&quot;multipart/form-data&quot;&gt;
                          
  &lt;s:textfield name=&quot;customer.customerID&quot; label=&quot;Customer ID&quot; size=&quot;15&quot;  /&gt;
  &lt;s:textfield name=&quot;customer.customerName&quot; label=&quot;Customer Name:&quot; maxlength=&quot;10&quot;/&gt;
  &lt;/s:form&gt;
  &lt;/body&gt;
  &lt;/head&gt;
  &lt;/html&gt;
  </code></pre>