title: Setting a ModelAttribute's date field when receiving a String from an <input type="date"> in Spring MVC
body: <p>I'm using Spring MVC and having an issue with submitting a form when the ModelAttribute for that form contains a <code>Date</code> field. When I make a POST my Apache Tomcat log gives me the following warning but no stack trace:</p>
  
  <pre><code>WARN    2017-10-12 11:51:05,574 [http-nio-8080-exec-7] org.springframework.web.servlet.PageNotFound  - Request method 'POST' not supported
  </code></pre>
  
  <p>My <code>@PostMapping</code> controller method never even gets called. The thing is, when I change the field from <code>Date</code> to <code>String</code>, the POST request goes through without any further changes.</p>
  
  <p>My form class:</p>
  
  <pre><code>public class MyForm {
      private Date myDate;
      // Other unrelated fields
  
      // getters + setters
  }
  </code></pre>
  
  <p>My JSP:</p>
  
  <pre><code>&lt;form:form method="POST" action="/new/MyForm" modelAttribute="myForm"&gt;
      // Unrelated inputs
  
      &lt;form:label path="myDate"&gt;Follow-up date&lt;/form:label&gt;
      &lt;form:input path="myDate" type="date"/&gt;
  
      &lt;input type="submit" name="complete" value="Submit"/&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>My Controller:</p>
  
  <pre><code>@InitBinder
  public void dataBinding(WebDataBinder binder) {
      SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
      CustomDateEditor dateEditor = new CustomDateEditor(dateFormat, true);
      binder.registerCustomEditor(Date.class, dateEditor);
  }
  
  @PostMapping(value="new/MyForm", params="complete")
  public ModelAndView submitMyForm(@ModelAttribute("myForm") MyForm form,
          BindingResult result) {
  
      if (result.hasErrors()) {
          return new ModelAndView("myURL");
      }
  
      return this.saveAndRedirect(form);
  }
  </code></pre>
  
  <p>If I take out the date input from the JSP completely, everything goes through and gets submitted as expected. If I change the <code>Date</code> type to <code>String</code> in the Form class, again, the form gets submitted (but I would need to convert the String to a Date manually each time in each controller that uses Date for database storage, and vice versa to display the retrieved Date).</p>
  
  <p>What am I doing wrong?</p>