简体   繁体   English

如何在JSF应用程序中检测客户端区域设置?

[英]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? 如何在我的代码中缺少Servlet并由JSF实现提供时,如何在JSF应用程序中使用ServletRequest.getLocale() I'm trying to use ServletContextListener , but is it possible to reach ServletRequest from ServletContextEvent ? 我正在尝试使用ServletContextListener ,但是可以从ServletContextEvent到达ServletRequest吗?

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. 我强烈建议你阅读教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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