title: How to add date field in Spring MVC
body: <p>If i want to use custom date editor i need few things to ask</p>
  
  <pre><code>1)In database do i have to set variable startDate as datetime or varchar
  2)IN Person class startDate is refered as Date or String
  </code></pre>
  
  <p>I have controller like this</p>
  
  <pre><code>@Controller
  public class MyController {
  
  protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
              SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
              CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
              binder.registerCustomEditor(Date.class, editor);
            }
  </code></pre>
  
  <p>in jsp form i have</p>
  
  <pre><code>&lt;td&gt;&lt;form:label path="startDate"&gt;date&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="startdate"/&gt;&lt;/td&gt;
  </code></pre>
  
  <p>But when i submit form , nothing happens</p>
  
  <p>this is the other methods in controller</p>
  
  <pre><code> @RequestMapping(value = "/persons/add", method = RequestMethod.GET)
      public String getAdd(Model model) {
          logger.debug("Received request to show add page");
  
          // Create new Person and add to model
          // This is the formBackingOBject
          model.addAttribute("personAttribute", new Person());
  
          // This will resolve to /WEB-INF/jsp/addpage.jsp
          return "hibernate/addpage";
      }
  
  
      @RequestMapping(value = "/persons/add", method = RequestMethod.POST)
      public String add(@Valid @ModelAttribute("personAttribute") Person person, BindingResult result) {
          logger.debug("Received request to add new person");
  
          if (result.hasErrors()) 
          return "hibernate/addpage";
          else
          personService.add(person);
  
          // This will resolve to /WEB-INF/jsp/addedpage.jsp
          return "hibernate/addedpage";
      }
  </code></pre>