Friends, Apprreciate your help to resolve this issue.
I am using BeanUtils.copyProperties to populate my DTO from my form bean. I am using DateLocaleConverter to convert date string of my formbean to util date of DTO. Somehow DateLocaleConverter does not use the format I am sending and gives me date in some other default format. I have registered DateLocaleConverter and it is getting invoked.
The only area of ambiguity might be the month and day getting mixed up. For example, when the date 10/12/06 is converted, does it get converted to October 12, or to December 10?
If this is being translated correctly, DateLocaleConverter is working. A java.util.Date doesn't have a format. If BeanUtils is translating your String into a java.util.Date, it's doing its job. You can then format the date however you want.
One thing you may not be aware of is that DateLocaleConverter only handles the String to Object conversion, not the object to String conversion. If you want the java.util.Date to be displayed in a specific format, you will have to use java.text.SimpleDateFormat to format the date string the way you want it.
Thanks for your reply. DateLocaleConverter is converting 10/12/2006 as Thu Oct 12 00:00:00 PDT 2006. Good news. I am passing pattern as MM/dd/yyyy and DateLocaleConverter has a parse() method which is using SimpleDateFormat to format the date in the supplied pattern. Anyway, I will try writing a CustomDateConverter and formatting. This should work converting either way right? Thanks
From what I read in the JavaDocs, the converters only affect the conversion from String to Object, not the other way around. Go ahead and play with it, though, and let us know what works and what doesn't.