wood burning stoves 2.0*
The moose likes Struts and the fly likes DateLocaleConverter  not using supplied pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "DateLocaleConverter  not using supplied pattern" Watch "DateLocaleConverter  not using supplied pattern" New topic
Author

DateLocaleConverter not using supplied pattern

H Ritwick
Greenhorn

Joined: Mar 15, 2006
Posts: 18
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.

String pattern = "MM/dd/yy";
Locale locale = Locale.getDefault();
DateLocaleConverter converter = new DateLocaleConverter(locale, pattern);

Any help is appreciated.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
H Ritwick
Greenhorn

Joined: Mar 15, 2006
Posts: 18
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
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DateLocaleConverter not using supplied pattern
 
Similar Threads
SimpleDateFormat and locale
Struts 1 localized date in MessageFormat string
Date locale setting
Working with Dates
digester question