title: Spring: Convert String from View to a Calendar Object
body: <p>How can I convert a string from a form input (easyui-datetimebox, in case) to a Calendar property in an object in Controller, autobinded by Spring?</p>
  
  <p>I've read <a href="http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/validation.html" rel="nofollow">http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/validation.html</a> but I couldn't find anything nearly right-to-the-point there.</p>
  
  <p>JSP:</p>
  
  <pre><code>&lt;input id="DeadLineDate"
    class="easyui-datetimebox" 
    name="DeadLineDate"
    value="${SessionDeadLineDate}"
    data-options="formatter:myformatter,
                  parser:myparser
  /&gt;
  </code></pre>
  
  <p>When submited, Spring validation throws an error:</p>
  
  <pre><code>Failed to convert property value of type java.lang.String to required type java.util.Calendar for property DeadLineDate; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Calendar] for property DeadLineDate: no matching editors or conversion strategy found.
  </code></pre>
  
  <p>PS: Spring 3</p>
  
  <p>Edit: adding controller's method to perform operation:</p>
  
  <pre><code>@Controller
  @RequestMapping("/project/MaintainProjectFrm")
  @SessionAttributes({"project","SessionDeadLineDate"})
  public class MaintainProjectController {
  
      /* ... many methods... */
  
      @RequestMapping(params = "update", method = RequestMethod.POST, produces={"text/plain; charset=UTF-8"})
      public String update(@ModelAttribute("project") Project project, 
                              BindingResult result, 
                                      SessionStatus status, 
                                          ModelMap model,
                                              HttpServletRequest req,
                                                  HttpServletResponse resp) throws IOException {
  
          projectValidator.validate(project, result);
  
          if (result.hasErrors()) {
               //has errors, in this case, that one shown in text above, which is rendered again in view (JSP)
              return "/project/MaintainProjectFrm";
          } else {
  
              try{
                  mpService.updateProject(project);
              }
              catch(Exception e){
                  resp.setStatus(500);
                  resp.getWriter().write("Error updating project: " + e.getMessage());
                  return "/project/MaintainProjectFrm";
              }
  
              status.setComplete();
  
          }
      }
  
      /* ... yet other methods ... */
  }
  </code></pre>