Custom Date Formatting with Spring Data Binders

It's relatively trivial to modify the way dates are formatted when they are bound to form fields with Spring. Just implement the initBinder method in your controller. Here's an example.

protected void initBinder(HttpServletRequest request,
                          ServletRequestDataBinder binder)
  throws Exception
{
  super.initBinder(request, binder);
  binder.registerCustomEditor(Date.class,
    "estimatedCompletionDate",
    new CustomDateEditor(new SimpleDateFormat( "M/d/yy"), true)
  );
}

Leave a comment

About this Entry

This page contains a single entry by Aaron published on June 13, 2005 1:28 AM.

Edit Multiple Records With Spring (and Velocity) is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.