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 ?
views:
3442answers:
3You could create a hidden input in your form and populate it using JavaScript when user selects date, then bind to this input in your command object.
Probably you will be using javascript anyway for things like checking correctness of the date, so why not format the ready to use date in one parameter.
Then you need to register a property editor that would convert from string "2008-05-20" to Date object.
then i would have three fields in my command object - year, month, day and would use standard spring validation for date checking
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...