title: Struts2 xml validation is not working
body: <p>Here is my Register-validation.xml</p>
  
  <pre><code>&lt;!DOCTYPE validators PUBLIC
  "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
  "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"&gt;
  &lt;validators&gt;
  
      &lt;validator type="requiredstring"&gt;
          &lt;param name="fieldname"&gt;userBean.username&lt;/param&gt;
          &lt;message&gt;User name is required.&lt;/message&gt;
      &lt;/validator&gt;
  
      &lt;validator type="required"&gt;
          &lt;param name="fieldname"&gt;profileBean.Age&lt;/param&gt;
          &lt;message&gt;Age is required.&lt;/message&gt;
      &lt;/validator&gt;
  
  &lt;/validators&gt;
  </code></pre>
  
  <p>Here is my form.</p>
  
  <pre><code>&lt;s:form action="register"&gt;
  
          &lt;label&gt;UserName&lt;/label&gt;
          &lt;s:textfield cssClass="formfield" name="userBean.username"
              label="User Name" /&gt;
          &lt;br /&gt;
          &lt;label&gt;Password&lt;/label&gt;
          &lt;s:password cssClass="formfield" name="userBean.password"
              label="Password" /&gt;
          &lt;br /&gt;
          &lt;label&gt;First Name&lt;/label&gt;
          &lt;s:textfield cssClass="formfield" name="profileBean.firstName"
              label="First Name" /&gt;
          &lt;br /&gt;
          &lt;label&gt;Last Name&lt;/label&gt;
          &lt;s:textfield cssClass="formfield" name="profileBean.lastName"
              label="Last Name" /&gt;
          &lt;br /&gt;
          &lt;label&gt;Age&lt;/label&gt;
          &lt;s:textfield cssClass="formfield" name="profileBean.age" label="Age" /&gt;
          &lt;s:submit /&gt;
      &lt;/s:form&gt;
  </code></pre>
  
  <p>Even though I not enter a value for username and age the form still keeps going in the success page. why is it not working?</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>struts.xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE struts PUBLIC
      "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
      "http://struts.apache.org/dtds/struts-2.0.dtd"&gt;
  
  &lt;struts&gt;
      &lt;constant name="struts.devMode" value="false" /&gt;
      &lt;constant name="struts.ui.theme" value="simple" /&gt;
  
      &lt;package name="basicstruts2" namespace="/Welcome" extends="struts-default"&gt;
          &lt;action name="index"&gt;
              &lt;result&gt;WEB-INF/index.jsp&lt;/result&gt;
          &lt;/action&gt;
  
          &lt;action name="HelloWorld" class="actions.HelloWorldAction"
              method="execute"&gt;
              &lt;result name="success"&gt;/HelloWorld.jsp&lt;/result&gt;
          &lt;/action&gt;
      &lt;/package&gt;
  
      &lt;package name="Registration" namespace="/" extends="struts-default"&gt;
          &lt;action name="register" class="actions.Register"
              method="execute"&gt;
              &lt;result name="success"&gt;/thankyou.jsp&lt;/result&gt;
          &lt;/action&gt;
      &lt;/package&gt;
  &lt;/struts&gt;
  </code></pre>
  
  <p>Profile Bean</p>
  
  <pre><code>package model;
  
  public class Profile {
      private String firstName;
      private String lastName;
      private int age;
  
      public String getFirstName() {
          return firstName;
      }
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
      public String getLastName() {
          return lastName;
      }
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
      public int getAge() {
          return age;
      }
      public void setAge(int age) {
          this.age = age;
      }
  
  
  
  }
  </code></pre>
  
  <p>and User Bean</p>
  
  <pre><code>package model;
  
  public class User {
      private String username;
      private String password;
      private int accountType;//Admin  - 0; User - 1;
      private Profile profile;
  
      public User(){
          accountType = 1;
      }
  
  
      public String getUsername() {
          return username;
      }
  
  
      public void setUsername(String username) {
          this.username = username;
      }
  
  
      public String getPassword() {
          return password;
      }
      public void setPassword(String password) {
          this.password = password;
      }
      public int getAccountType() {
          return accountType;
      }
      public void setAccountType(int accountType) {
          this.accountType = accountType;
      }
      public Profile getProfile() {
          return profile;
      }
  
      public void setProfile(Profile profile) {
          this.profile = profile;
      }
  
  
  }
  </code></pre>
  
  <p>Register Action</p>
  
  <pre><code>public class Register extends ActionSupport  implements ServletRequestAware{
  
      public String execute(){
  
          userBean.setProfile(getProfileBean());
          return "success";
      }
  
      private User userBean;
      private Profile profileBean;
      HttpServletRequest request;
  
      public User getUserBean() {
          return userBean;
      }
  
      public void setUserBean(User userBean) {
          this.userBean = userBean;
      }
  
      public Profile getProfileBean() {
          return profileBean;
      }
  
      public void setProfileBean(Profile profileBean) {
          this.profileBean = profileBean;
      }
  
      public void setServletRequest(HttpServletRequest request) {
          this.request = request;
      }
  
      public HttpServletRequest getServletRequest() {
          return this.request;
      }
  }
  </code></pre>