title: How to properly validate method in struts by extending Action support class?
body: <p>Here is my snippet of code,</p>
  
  <pre><code>public class LoginAction extends ActionSupport {
       private String userId;
   private String password;
       ...........
  
       public void validate() {
      if (getUserId().length() == 0) {
          addFieldError("userId",getText("userId.required"));
      } 
      else if (!getUserId().equals("va1525252")) {
          addFieldError("userId", "Invalid User");
      }
      if (getPassword().length() == 0) {
          addFieldError("password",getText("password.required"));
      }
  }
  </code></pre>
  
  <p>when userId field is empty I get error saying <strong>Login Name is required</strong> I have never set such error message , so what is the problem here?</p>
  
  <p>here is our LoginAction.properties file which is in the same package as LoginAction class</p>
  
  <pre><code>password.required = Password is required
  userId.required = UserId is required
  </code></pre>
  
  <p>here is our screenshot of login page when clicked on submit with fields empty
  <img src="https://i.stack.imgur.com/TQL4S.jpg" alt="Login Page"></p>