Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ratish Vichithran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
Ratish Vichithran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, try something like this:


Please make sure what is the language code and country code for "Frans/French"
 
Ratish Vichithran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic