title: How to validate two forms on one page in Struts 2 using validate method
body: <p>I'm new to Struts2 and I want to validate two form tags on the same page:</p>
  
  <ol>
  <li>I have a <code>userId</code> and <code>password</code> fields on top for <code>Login</code> action</li>
  <li>At center I have another form tag to register a new user </li>
  </ol>
  
  <p>Now my problem is when I apply <code>addfielderror()</code> to login i.e (<code>username</code> and <code>password</code> fields) and fill the registration form as new user won't have <code>userId</code> and <code>password</code> to login. It shows an error to the login form tag which is blank at that time. That is wrong for that action and it happens for vice-verse. So, what should I do, when I'm doing login it should check only login action and when I'm registering it should check for register action?</p>
  
  <p><strong>This is my code for <code>Login</code> action:</strong></p>
  
  <pre><code>&lt;s:form  method="Post" action="Login"&gt;
      &lt;s:textfield   type="text" class=" input-small span2" name="login.Email"  placeholder="Email"&gt;&lt;/&lt;s:textfield &gt;
      &lt;s:password type="password" class=" input-small span2" name="login.Pass"  placeholder="Password"&gt;&lt;/ s:password&gt;
      &lt;button type="submit" class="btn"&gt;Sign in&lt;/button&gt; &lt;br /&gt;      
  &lt;/s:form&gt;
  </code></pre>
  
  <p><strong>This is Registeration code:</strong></p>
  
  <pre><code>&lt;s:form method="POST" action="Registor"&gt;
     &lt;s:textfield class="span1" id="fname" name="FirstName" placeholder="First Name"&gt;&lt;/s:textfield&gt;  
     &lt;s:textfield class="span1" id="Lname" name="LastName" placeholder="Last Name"&gt;&lt;/s:textfield&gt;  
     &lt;s:password class="span2" id="password" placeholder="Password" name="Password"&gt;&lt;/s:password&gt;&lt;br /&gt;       
     &lt;s:textfield class="span2" id="email" placeholder="Email ID" name="Email_Id"&gt;&lt;/s:textfield&gt;
     &lt;br /&gt;
     &lt;s:select headerKey="1" id="gender" headerValue="Select Gender" list="#@java.util.HashMap@{'Male':'Male','Female':'Female'}" name="Gender"&gt;&lt;/s:select&gt;&lt;br /&gt;                   
     &lt;button type="submit" id="submit" &gt;Submit&lt;/button&gt;&lt;br /&gt;                    
  &lt;/s:form&gt;
  </code></pre>
  
  <p><strong>Validate Code:</strong></p>
  
  <pre><code>public void validate() {    
    //This is for login action            
    if((login.getPassword().equals("foobar")){
      addActionMessage(SUCCESS);  
    }else{
      addFieldError("Password", "Password should be greater then 6"); 
    }                         
    //This is for registration action              
    if((user.getPassword() == null) || (user.getPassword().length() &lt; 6)){
      addFieldError("Password", "Password should be greater then 6"); 
    }       
  }  
  </code></pre>
  
  <p>Now, when I enter correct password like here its <code>"foobar"</code> it shows an error to the field on registration form</p>
  
  <pre><code>"Password should be greater then 6"
  </code></pre>
  
  <p>instead it should have shown login success message of login action.</p>
  
  <p><strong><code>Struts.xml</code>:</strong></p>
  
  <pre><code>&lt;package name="default" extends="struts-default" &gt;
      &lt;action name="Login" class="org.register.customers.RegisterUserAction" method="getLogin"&gt;
          &lt;result name="input"&gt;index.jsp&lt;/result&gt;
          &lt;result name="success"&gt;UserLoging.jsp&lt;/result&gt;
          &lt;result name="error"&gt;error.jsp&lt;/result&gt;
      &lt;/action&gt;
      &lt;action name="Registor"  class="org.register.customers.RegisterUserAction" method="getRegistor"&gt;
          &lt;result name="input"&gt;index.jsp&lt;/result&gt;
          &lt;result name="success"&gt;RegistorSuccess.jsp&lt;/result&gt;
          &lt;result name="error"&gt;index.jsp&lt;/result&gt; 
      &lt;/action&gt;
  &lt;/package&gt;
  </code></pre>