Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC : Binding 3 dropdowns to a date property in SimpleFormController

How should I configure the class to bind three dropdowns (date, month, year) to a single Date property so that it works the way it works for 'single request parameter per property' scenario ? I guess a should add some custom PropertyEditors by overriding initBinder method. What else ?

like image 289
axk Avatar asked Oct 02 '08 09:10

axk


1 Answers

Aleksey Kudryavtsev: you can override the onBind method in your controller, i which you cant fiddle something special in command object, like

dateField = new SimpleFormat("YYYY-mm-dd").parse(this.year + "-" + this.month + "-" this.day);

or:

Calendar c = Calendar.getInstance();
c.set(year, month, day);
dateField = calendar.getTime();

but i'd rather do validation in javascript and use some available date picker component, there are plenty of them...

like image 141
miceuz Avatar answered Oct 11 '22 11:10

miceuz