wood burning stoves 2.0*
The moose likes Struts and the fly likes bean:write not using locale settings while formatting a date value. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean:write not using locale settings while formatting a date value." Watch "bean:write not using locale settings while formatting a date value." New topic
Author

bean:write not using locale settings while formatting a date value.

Ratish Vichithran
Greenhorn

Joined: Feb 27, 2009
Posts: 9
I have to display a date in the format 'MMMM dd, yyyy'. This works only when the locale carries 'en' as the language. It shows English names for months even though the locale has been changed to French, Canada.

The following is the code I have written in my jsp.



I am changing the locale in the session with the attribute named under Globals.LOCALE_KEY.


I read under the struts tag reference the following comment,

If format attribute exists then value will be formatted on base of format string from format attribute and default system locale.


What does default system locale mean, is it the locale of the OS?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Ratish Vichithran wrote:

I think you need to provide some extra attributes. namely:

local and bundle

bundle

The name of the application scope bean under which the MessageResources object containing our messages is stored.


locale

The name of the session scope bean under which our currently selected Locale object is stored.

Ratish Vichithran wrote:What does default system locale mean, is it the locale of the OS?

YES
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html#getDefault()


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ratish Vichithran
Greenhorn

Joined: Feb 27, 2009
Posts: 9
hi Sagar, thanks for the reply

I used the following code,



but still it doesn't work.

I believe I don't have to use bundle since I have no values that are stored in the MessageResources file that has to be used here.

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

OK, try something like this:


Please make sure what is the language code and country code for "Frans/French"
Ratish Vichithran
Greenhorn

Joined: Feb 27, 2009
Posts: 9
It still didn't work.

But that's fine. I found a work around.

I created a class with a static method and the parameters to the method are the locale, date value and the format. And I called that method in my jsp.

Now it is working fine...

Thanks for your replies Sagar.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Ratish Vichithran wrote:It still didn't work.

I didn't tried i18n in Struts, its just guess workaround I was giving.

Ratish Vichithran wrote:But that's fine. I found a work around.
I created a class with a static method and the parameters to the method are the locale, date value and the format. And I called that method in my jsp.

And better you called that Utility class at server side action class before setting the bean properties, because its ill practice to call Java code in JSP. Don't use Scriptlets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean:write not using locale settings while formatting a date value.