title: validate method in ActionForm subclass when it is called
body: <p>Learning Struts 1.1 using "Jakarta Struts for Dummies" book while reading about <code>ActionForm</code> it says </p>
  
  <pre><code>validate method: Is called after the `ActionServlet` populates the
  form with the request properties and before the form is passed to a particular
  `Action` class for processing
  </code></pre>
  
  <p>actually we submit the form with properties(say username or password) and these are populated in request. but here it is saying that <code>ActionServlet</code> is populates the form? </p>
  
  <p>I think here form means <code>ActionForm</code> or its subclass rite, correct me if I am wrong.</p>
  
  <p><strong>Here is the form:</strong></p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
  &lt;%-- JSTL tag libs --%&gt;
  &lt;%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %&gt;
  &lt;%-- Struts provided Taglibs --%&gt;
  &lt;%@ taglib prefix="html" uri="/WEB-INF/struts-html-el.tld" %&gt;
  &lt;html:html locale="true"/&gt;
  &lt;head&gt;
      &lt;fmt:setBundle basename="ApplicationResources" /&gt;
      &lt;title&gt;&lt;fmt:message key="login.title"/&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;html:errors property="login"/&gt;
  &lt;html:form action="login.do" focus="userName"&gt;
      &lt;table align="center"&gt;
          &lt;tr align="center"&gt;
              &lt;td&gt;&lt;H1&gt;&lt;fmt:message key="login.message"/&gt;&lt;/H1&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr align="center"&gt;
              &lt;td&gt;
                  &lt;table align="center"&gt;
                      &lt;tr&gt;
                          &lt;td align="right"&gt;
                              &lt;fmt:message key="login.username"/&gt;
                          &lt;/td&gt;
                          &lt;td align="left"&gt;
                              &lt;html:text  property="userName" 
                                          size="15" 
                                          maxlength="15" /&gt;
                              &lt;html:errors property="userName" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;   
                      &lt;tr&gt;
                          &lt;td align="right"&gt;
                              &lt;fmt:message key="login.password"/&gt;
                          &lt;/td&gt;
                          &lt;td align="left"&gt;
                              &lt;html:password  property="password" 
                                              size="15" 
                                              maxlength="15" 
                                              redisplay="false"/&gt;
                              &lt;html:errors property="password" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;   
                      &lt;tr&gt;
                          &lt;td colspan="2" align="center"&gt;
                              &lt;html:submit&gt;
                                  &lt;fmt:message key="login.button.signon"/&gt;
                              &lt;/html:submit&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/html:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Here is the <code>LoginForm</code>:</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>import javax.servlet.http.HttpServletRequest;
  
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  
  /**
   * @author kiran
   *
   */
  public class LoginForm extends ActionForm 
  {
      private String userName;
      private String password;
      int count=0;
  
      /**
       * Resets data fields to initial values on loginform
       * @param mapping
       * @param request
       */
      public void reset(ActionMapping mapping, HttpServletRequest request)
      {
          password = "";
          userName = "";
          count++;
          System.out.println("reset method is called"+count+ " time/s");
      }
  
  
      /**
       * Performs validation of data on loginform
       * @param mapping
       * @param request
       * @return ActionErrors
       */
      public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
      {
          System.out.println("validate method is called"+count+" time/s");
          System.out.println(getUserName());
          ActionErrors errors = new ActionErrors();
  
          if((userName == null) || (userName.length() &lt; 1))
              errors.add("userName", new ActionError("error.username.required"));
          if((password == null) || (password.length() &lt; 1))
              errors.add("password", new ActionError("error.password.required"));
  
          return errors;
  
      }
      /**
       * @return String
       */
      public String getPassword() {
          return password;
      }
  
      /**
       * @return String
       */
      public String getUserName() {
          return userName;
      }
  
      /**
       * @param string
       */
      public void setPassword(String string) {
          password = string;
      }
  
      /**
       * @param string
       */
      public void setUserName(String string) {
          userName = string;
      }
  
  }
  </code></pre>