This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Determining Locale .... How? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Determining Locale .... How?" Watch "Determining Locale .... How?" New topic
Author

Determining Locale .... How?

Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
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
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2841
    
  11

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.
Chintan Rajyaguru
Ranch Hand

Joined: Aug 19, 2001
Posts: 341
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


ChintanRajyaguru.com
SOADevelopment.com - Coming soon!
 
wood burning stoves
 
subject: Determining Locale .... How?
 
Similar Threads
Hibernate join and key tag
Locale specific JSP
Override request headers
language propertis to xml properties
locales and jsf