title: Can't clear form input after reject
body: <p>I am having trouble clearing a form input field using Bean Validation when a constraint is validated.  I have a form input that may not exceed 50 characters, so I want to display a message and clear the field if the user hacks the page and exceeds the character limit.  I have tried just clearing the bound field, but this does not work.  No matter what I do, the cached value (the value that was rejected by bean validation) always remains in the input field.  My code is as follows:</p>
  
  <p>JSP:</p>
  
  <pre><code>&lt;form:form action="submit.do" method="POST" commandName="obj"&gt;
      &lt;form:input id="field1" path="field1" cssClass="box" size="50" maxlength="50"/&gt;
      &lt;p&gt;&lt;input class="action" type="submit" name="enter.x" value="Submit" /&gt;&lt;/p&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>MODEL:</p>
  
  <pre><code>public class Obj{
      @Length(max=50, message="Length invalid.")
      private String field1;
  
      // Getter and setter
  }
  </code></pre>
  
  <p>CONTROLLER:</p>
  
  <pre><code>@SessionAttributes ({"obj"}) 
  public class NavController{ 
  
      @RequestMapping(value="show.do", method=RequestMethod.POST)
      public ModelAndView submitUpdateObj(
              HttpServletRequest request
              , HttpServletResponse response
              ,@ModelAttribute
              @Valid
              Obj obj
              ,BindingResult result
      ) {
          ModelAndView mav = new ModelAndView();
  
          if(result.hasErrors()){
              // clear bound value
              obj.setField1("");
  
              // add error messages to request
              mav.setViewName("update");
          }else{
              mav.setViewName("register");
          }
  
  
          return mav;
      }
  
  }
  </code></pre>
  
  <p>I am able to get this working by creating a custom Validator and instantiating/calling a DataBinder in the controller, but I am trying to avoid programmatically validating this object (no nested if/else logic).  It seems that as soon as bean validator rejects a field, there is no way to clear it.  You must clear the field before it is rejected (which is why the custom validator method will work).  Using the method above, the validation/rejection occurs before I can get a hold of the object and I can't get past the cached field value.  Any help would be greatly appreciated.</p>
  
  <p><strong>* UPDATE *</strong>
  The following link contains a very similar problem:</p>
  
  <p><a href="http://forum.springsource.org/showthread.php?50762-Clear-form-field-after-failed-validation" rel="nofollow">http://forum.springsource.org/showthread.php?50762-Clear-form-field-after-failed-validation</a></p>
  
  <p>The solution provided is exactly what I would prefer NOT to do.</p>