简体   繁体   中英

How to detect client locale in JSF application?

How can I use ServletRequest.getLocale() in JSF application, when Servlet is absent in my code and is provided by JSF implementation? I'm trying to use ServletContextListener , but is it possible to reach ServletRequest from ServletContextEvent ?

Anyway, what is the correct approach?

FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();

The correct way in my opinion is to provide the links on your home page for various locales your application needs to support. This is less intrusive for the end user. Otherwise the end user has to keep changing the locales browser specific way. Also different browsers send the locale different ways to the server which is also problematic depending on your usecase.

I strongly suggest you go through this tutorial.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM