与JSF无效后,保持当前的语言环境
此方法使会话无效并使用户返回主页。
public String restart() {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
return "/index?faces-redirect=true";
}
因此,用户选择的区域设置会被忘记,应用程序会切换回浏览器的默认区域设置。 我希望即使在会话失效后区域设置也保持不变。该方法现在看起来像:
public String restart() {
Locale currLocale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
FacesContext.getCurrentInstance().getViewRoot().setLocale(currLocale);
return "/index?faces-redirect=true";
}
但区域设置仍然切换回浏览器的默认值。我怎样才能实现我的目标?
This method invalidates the session and gets the user back to the home page.
public String restart() {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
return "/index?faces-redirect=true";
}
As a consequence, the locale chosen by the user is forgotten and the app switches back to the default locale of the browser. I want that the locale remains the same even after the session invalidation. The method now looks like:
public String restart() {
Locale currLocale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
FacesContext.getCurrentInstance().getViewRoot().setLocale(currLocale);
return "/index?faces-redirect=true";
}
But the locale still switches back to the browser's default. How can I achieve my goal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论