• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Determining Locale .... How?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an EJB app and would like to know how I determine what the current locale setting is. If I call Locale.getDefault() I get the default JVM Locale. All of my resource strings have been externalized into resource bundles.

Any help is greatly appreciated.

Regards,
Joe
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Generally speaking, you don't get the locale in EJB code. One of the strengths of the J2EE platform is the separation of business and presentation logic. The EJBs should be doing business logic, and the locale is only relevant for presentation done by JSPs or servlets (if presentation is handled on the server at all).

Usually, the user will set a preferred language for the site, which you can save in a user profile on the server or in a cookie. Something in the HTTP request may indicate the user's locale, but I'm not sure.
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with the previous poster. Locale is usually related to internationalization, which EJB should be independent of. I can think of some usecases where you will have different logic based on locale. If you must, you can pass locale from the presentation layer.

Locale locale = request.getLocale();

This method is actually defined in the ServletRequest interface. The value you receive will depend on the the locale set when the http request (or user's browser). Locale.getDefault() always returns the locale of the JVM and hence should not be trusted.

Long story short, pass the locale to the business layer if you have to. BUT try not to pass the Locale object itself, pass the String value that way business layer is less dependent on the [http] presentation layer

C
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic