we have an JSF2.0 / EJB3.0 Application. Is it possible to access user’s language/locale from within a StatelessSessionBean? For example something like that?
@Stateless
@Local(MyService.class)
public class MyServiceBean implements MyService {
@Resource
private SessionContext context;
public void doSomething() {
Principal principal = context.getCallerPrincipal();
// how to get acccess to user's language ?
Locale locale = ...
}
}
Of course it is possible to pass the Locale from web tier to ejb tier by parameter to each method. But is this the smartest variant?
Is there a better solution similar to context.getCallerPrincipal();
I am looking for somthing like: context.getCallerLocale();
Thanks for your help.
Viktor
There is no such standard feature. One technique is to use a thread-local, but you need to carefully ensure you call .remove() to avoid causing problems with your container’s thread pool. The only other alternative is to use a vendor-specific feature, such as WebSphere Application Server’s Internationalization service.