title: Spring 3.x validation error binding on fieldName fails
body: <p>I'm using Spring 3.2.8-RELEASE version. This may be a bug but need confirmation.</p>
  
  <p>My Controller:</p>
  
  <pre class="lang-java prettyprint-override"><code>@SessionAttributes( { "exampleForm", "testForm", "staticContent" } )
  @Controller
  @RequestMapping( value = "/action" )
  public class ExampleController extends BaseController {
  
      @Autowired
      private ExampleFormValidator validator;
  
      @RequestMapping(value = "/subAction", method = RequestMethod.GET)
      public String doGet(@ModelAttribute ExampleForm exampleForm,
      @ModelAttribute TestForm testForm, @ModelAttribute StaticContent staticContent) {
          return "example.tile";
      }
  
      @ModelAttribute("exampleForm")
      public ExampleForm exampleForm() {
          return new ExampleForm();
      }
  
      @InitBinder("exampleForm")
      public void initBinder(WebDataBinder binder) {
          binder.setValidator(this.validator);
      }
  
      @RequestMapping(value = "/subAction", method = RequestMethod.POST, params = "submitAction=ok")
      public String doAction(@Validated @ModelAttribute ExampleForm exampleForm,
              BindingResult formBinding, @ModelAttribute TestForm testForm,
              @ModelAttribute StaticContent staticContent, SessionStatus sessionStatus,
              RedirectAttributes ra, Model model) {
              if (formBinding.hasErrors()) {
                  return "example.tile";
              }
          }
  
  }
  </code></pre>
  
  <p>My Validator:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class ExampleFormValidator implements Validator {
  
      public boolean supports( Class&lt;?&gt; clazz ) {
          return ExampleForm.class.equals( clazz );
      }
  
      public void validate( Object target, Errors errors ) {
          ExampleForm form = (ExampleForm) target;
          if (form.getFieldName() == null) {
              error.rejectValue("fieldName", form.getFieldName(), "common.field.required");
          }
      }
  }
  </code></pre>
  
  <p>Example Form with one field for brevity:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class ExampleForm {
      private String fieldName;
  
      public String getFieldName() {
          return fieldName;
      }
  
      public void setFieldName(String fieldName) {
          this.fieldName = fieldName;
      }
  }
  </code></pre>
  
  <p>Static Content Form that has the same field name as in example form above BUT it is of type Date as opposed to String.</p>
  
  <pre class="lang-java prettyprint-override"><code>public class StaticContent {
      private Date fieldName;
  
      public Date getFieldName() {
          return fieldName;
      }
  
      public void setFieldName(Date fieldName) {
          this.fieldName = fieldName;
      }
  }
  </code></pre>
  
  <p>The StaticContent has static content that gets displayed on the top of the JSP. The example form element holds the form elements. </p>
  
  <p>The GET method works fine and displays the JSP. When I submit the form without providing any input, it invokes the example validator, adds the rejected value but fails with following error. As you can see it is trying to bind the rejected value to staticContent object as opposed to exampleForm. What am I doing wrong?</p>
  
  <p><code>
  14:39:04,605 INFO  [STDOUT] [13 Jan 2015 14:39:04,602] TRACE [ServletInvocableHandlerMethod] Error resolving argument [3] [type=com.personal.example.bo.StaticContent]
  HandlerMethod details: 
  Controller [com.personal.example.controller.ExampleController]
  Method [public java.lang.String com.personal.example.controller.ExampleController.doAction(com.personal.example.form.ExampleForm,org.springframework.validation.BindingResult,com.personal.example.form.TestForm,com.personal.example.bo.StaticContent,org.springframework.web.bind.support.SessionStatus,org.springframework.web.servlet.mvc.support.RedirectAttributes,org.springframework.ui.Model) throws com.personal.example.exception.ApplicationException]</p>
  
  <p>org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
  Field error in object 'staticContent' on field 'fieldName': rejected value []; codes [typeMismatch.staticContent.fieldName,typeMismatch.fieldName,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [staticContent.fieldName,fieldName]; arguments []; default message [fieldName]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'fieldName'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type java.util.Date for value ''; nested exception is java.lang.IllegalArgumentException]
  </code></p>
  
  <p>I have tried several different things without trying to rename the 'fieldName' in ExampleForm</p>
  
  <ol>
  <li>Tried to pre-qualify the field name in error.rejectValue method call with exampleForm and obviously it did not like it and throws org.springframework.beans.NotReadablePropertyException</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>error.rejectValue("exampleForm.fieldName", form.getFieldName(), "common.field.required");
  </code></pre>
  
  <ol start="2">
  <li>I have tried to pre-qualify the @ModelAttribute in the POST method in controller and that didn't help eihter</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value = "/subAction", method = RequestMethod.POST, params = "submitAction=ok")
      public String doAction(@Validated @ModelAttribute ("exampleForm") ExampleForm exampleForm,
              BindingResult formBinding, @ModelAttribute TestForm testForm,
              @ModelAttribute StaticContent staticContent, SessionStatus sessionStatus,
              RedirectAttributes ra, Model model) {
  }
  </code></pre>