HowTo: Bind an input field to a Date property using Spring's SimpleFormController
Read the article on my new blog under http://blog.js-development.com/2009/04/howto-bind-input-field-to-date-property.html
If you're using the Spring SimpleFormController for binding your Java bean object to the UI, you may come across the case where you want to create a binding between an input field (where the user inputs a date) and your bean's Date property:
<form:input path="expiryDate" size="15" />
You will notice that you cannot just do it as normal, but to let your SimpleFormController accept the binding, you have to override the following method:
@Override
protected void initBinder(PortletRequest request, PortletRequestDataBinder binder) throws Exception {
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
df.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
super.initBinder(request,binder);
}


1 Comments:
cool Post !!! Saved my life
Post a Comment