title: Trying to use spring MVC validator with parent child class relation.Getting an error more details below
body: <p>I am actually trying to validate a form named user.jsp which .the "Class User" .. has a reference of "class inuser"(this class has only one attribute qualification)which is another class. when i keep the qualification field "" blank the system gives a stack trace which i have pasted below. Please help if possible i will be thankfull.</p>
  
  <pre><code>package net.roseindia.web;
  
  public class User {
  
     public User(){
        iu=new inuser();
     }
  
  
  private String name;    
  private String emailid;
  private String dob;
  private String address;
  private inuser iu;
  private String contact;
  
  
  public String getDob() {
      return dob;
  }
  public void setDob(String dob) {
      this.dob = dob;
  }
  
  public String getContact() {
      return contact;
  }
  
  public void setContact(String contact) {
      this.contact = contact;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  
  }
  public String getEmailid() {
      return emailid;
  }
  
  public void setEmailid(String emailid) {
      this.emailid = emailid;
  }
  public String getAddress() {
      return address;
  }
  
  public void setAddress(String address) {
      this.address = address;
  }
      public void setIu(inuser iu) {
           this.iu = iu;
      }
      public inuser getIu() {
           return iu;
      }
  }
  </code></pre>
  
  <p>then my inuser class:</p>
  
  <pre><code> public class inuser {
   public inuser() {} 
   private String qualification;
  
   public void setQualification(String qualification) {
  this.qualification = qualification;
   }
  
  public String getQualification() {
  return qualification;
  }
  }
  </code></pre>
  
  <p>this is how my form is partly:</p>
  
  <pre><code> &lt;tr&gt;
   &lt;td&gt;Qualification:&lt;/td&gt;
   &lt;td&gt;&lt;form:input path="iu.qualification"/&gt;&lt;/td&gt;
   &lt;td&gt;&lt;font color="red"&gt;&lt;form:errors path="iu.qualification"/&gt;&lt;/font&gt;&lt;/td&gt;
   &lt;/tr&gt;
  </code></pre>
  
  <p>validation class :</p>
  
  <pre><code>import java.util.regex.*;
  
  import org.springframework.validation.Errors;
  import org.springframework.validation.Validator;
  
  import net.roseindia.web.User;
  
  public class UserValidator implements Validator {
  
  @Override
  public boolean supports(Class clazz) {
      return User.class.isAssignableFrom(clazz);
  }
  public void validate(Object obj, Errors errors) {
      User user = (User) obj;     
  
      if ((user.getEmailid() != "") || (user.getEmailid().length()) != 0)       
  
      {           
          Pattern p=Pattern.compile(".+@.+\\.[a-z]+");
          Matcher m=p.matcher(user.getEmailid());
          boolean b=m.matches();
          if(b!=true)
          {
     errors.rejectValue("emailid", "error.is.not.valid", "Email ID does not   
     Valid");         
          }
      }
  
      if ((user.getContact() != "") || (user.getContact().length()) != 0) 
  
     {            
              Pattern pattern = Pattern.compile("\\d{1}-\\d{4}-\\d{6}");
              Matcher matcher = pattern.matcher(user.getContact());
              boolean con=matcher.matches();
              if(con!=true)
                  {
                      errors.rejectValue("contact",   
       "error.is.not.valid", "Enter Contact Number Like 0-9999-999999");
                  }
      }
      if ((user.getDob() != "") || (user.getDob().length()) != 0) {           
          Pattern pattern = Pattern.compile("\\d{2}/\\d{2}/\\d{4}");
          Matcher matcher = pattern.matcher(user.getDob());
          boolean DOB=matcher.matches();
          if(DOB!=true)
              {
                  errors.rejectValue("dob", "error.is.not.valid", 
     "Enter Date of birth Like 01/02/1986 ");
              }
      }
      if (user.getName() == null || user.getName().length() == 0) {
          errors.rejectValue("name", "error.empty.field", "Please Enter Name");
      }        
      if (user.getDob() == null || user.getDob().length() == 0) {
          errors.rejectValue("dob", "error.empty.field", "Please Enter Date Of Birth");
      }        
      if (user.getContact() == null || user.getContact().length() == 0) {
          errors.rejectValue("contact", "error.empty.field", "Please Enter Contact 
      Number");
      }        
      if (user.getEmailid() == null || user.getEmailid().length() == 0) {
          errors.rejectValue("emailid", "error.empty.field", "Please Enter Email ID");
      }
      //====&gt;&gt;&gt;here===&gt;&gt;      if (user.getIu().getQualification()=="" ) {
          errors.rejectValue("qualification", "error.empty.field", "Please Enter   
      Qualification");
      }
      if (user.getAddress() == null || user.getAddress().length() == 0) {
          errors.rejectValue("address", "error.empty.field", "Please Enter Address");
      }
      }
      }
  </code></pre>
  
  <p>myu statck trace when i leave qualification field blank (i.e) the    field from the inuser class </p>
  
  <pre>
          org.springframework.web.util.NestedServletException: Request processing failed; 
          nested exception is org.springframework.beans.NotReadablePropertyException:    
          Invalid property 'qualification' of bean class [net.roseindia.web.User]: Bean  
          property 'qualification' is not readable or has an invalid getter method: Does 
          the  return type of the getter match the parameter type of the setter?
  
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  
  
  root cause 
  
  org.springframework.beans.NotReadablePropertyException: Invalid property 'qualification' of bean class [net.roseindia.web.User]: Bean property 'qualification' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
      org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:540)
      org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:532)
      org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:79)
      org.springframework.validation.AbstractBindingResult.rejectValue(AbstractBindingResult.java:102)
      org.springframework.validation.AbstractErrors.rejectValue(AbstractErrors.java:122)
      org.springframework.validation.BindException.rejectValue(BindException.java:126)
      net.roseindia.web.UserValidator.validate(UserValidator.java:59)
      org.springframework.validation.ValidationUtils.invokeValidator(ValidationUtils.java:63)
      org.springframework.web.servlet.mvc.BaseCommandController.bindAndValidate(BaseCommandController.java:395)
      org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:263)
      org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
      org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  </pre>