NavigationHandler.handleNavigation() 是否清除闪光灯?
我正在使用 JSF2.0 Mojarra 2.0.2。
我有一种方法可以注销用户并将注销消息放入 Flash 中,然后转发到登录页面(其中有一个打印 Flash 的 div)。但是,当我由于某种原因使用 navigationHandlers handleNavigation 方法时,Flash 未显示。我有一个类似的方法,如果用户未登录,则将其转发到登录页面。
如果我通过 h:link 处理导航并直接调用注销方法,则 Flash 会正常显示,但如果我使用handleNavigation()方法,由于某种原因闪光灯被清除。
有问题的代码是:
public void performLogout()
{
getFacesContext().getExternalContext().invalidateSession();
setCurrentUser(null);
getFlash().put("notice", "Successfully logged out.");
super.getFacesContext().getApplication().getNavigationHandler()
.handleNavigation(getFacesContext(), null, "login");
}
有什么方法可以在像这样导航时保持闪光灯吗?
谢谢。
编辑:我相信这个问题与另一个问题有关,涉及当 xhtml 页面位于不同目录中时重定向期间 Flash 不被保留的问题: http://java.net/jira/browse/JAVASERVERFACES-1635
I am using JSF2.0 Mojarra 2.0.2.
I have a method that logs out a user and puts a logout message in the flash, forwards to the login page (which has a div that prints out the flash). However, when I use navigationHandlers handleNavigation method for some reason the flash is not being displayed. I have a similar method that forwards a user to the login page if he/she isn't logged in.
If I handle the navigation through an h:link and just call the logout method directly, the flash is displayed as normal, but if I use the handleNavigation() method, the flash is cleared for some reason.
The code in question is:
public void performLogout()
{
getFacesContext().getExternalContext().invalidateSession();
setCurrentUser(null);
getFlash().put("notice", "Successfully logged out.");
super.getFacesContext().getApplication().getNavigationHandler()
.handleNavigation(getFacesContext(), null, "login");
}
Is there some way I can keep the flash when navigating like this?
thanks.
Edit: I believe this issue is related to another issue involving the flash not being preserved during redirects when xhtml pages are in different directories: http://java.net/jira/browse/JAVASERVERFACES-1635
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说得对。
JSF 2 flash 范围目前存在极大的错误,并且根据规范,可能仍然几乎无法使用:http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/index.html
如果您想要一个按如下方式工作的 Flash 作用域,请考虑使用 CDI,并且Seam Faces 的 flash 范围 - http:// /docs.jboss.org/seam/3/faces/reference/snapshot/en-US/html_single/#flashscoped
——林肯
You're right.
The JSF 2 flash scope is currently extremly buggy, and based on the specification, will probably remain almost unusable: http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/index.html
If you'd like a flash scope that works as follows, consider using CDI, and the flash scope from Seam Faces - http://docs.jboss.org/seam/3/faces/reference/snapshot/en-US/html_single/#flashscoped
--Lincoln