PDA

View Full Version : CustomDateEditor and dates with or without time of day


kajh
Aug 13th, 2007, 01:34 PM
Hi!

I have a date property for which the user in the webinterface can type in the date both with and without time of day. i.e. both

SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
SimpleDateFormat dateFormatVerbose = new SimpleDateFormat("dd.MM.yyyy HH:mm");

is legal date formats. Time of day is optional.

I know how to register a CustomDateEditor for one of these formats, but how can I make the binder accept dates in both formats, depending on what the user choose to use?

Any hints for where to look? :)


-Kaj :)

kajh
Aug 13th, 2007, 04:29 PM
I solved this by creating a CustomDateEditorMultipleDateFormats with the following constructor:


public CustomDateEditorMultipleDateFormats(List<DateFormat> dateFormats, boolean allowEmpty)



-Kaj :)