views:

3442

answers:

3

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 ?

+1  A: 

You 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.

miceuz
Thanks for answer. It is a good idea. But is there a way to do it on the server side ?
axk
A: 

then i would have three fields in my command object - year, month, day and would use standard spring validation for date checking

miceuz
How would you convert these three fields to a Date property?
axk
+4  A: 

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...

miceuz