How to detect client locale in JSF application?

元气小坏坏 提交于 2019-12-10 11:33:24

问题


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?


回答1:


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

?




回答2:


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.



来源:https://stackoverflow.com/questions/4332700/how-to-detect-client-locale-in-jsf-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!