使用 ViewScoped bean 注销 JSF

标签 jsf omnifaces view-scope

在我的应用程序中,我有一个顶部栏,其中有一个调用 bean 方法的注销按钮

public String logout(){
    FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
    return Navigator.goTo("/index.xhtml");
}

它运行良好,但我有一个特定的页面,它因此异常而失败

2014-01-23T15:17:42.405+0100|WARNING: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
    at org.jboss.weld.context.beanstore.http.AbstractSessionBeanStore.getLockStore(AbstractSessionBeanStore.java:120)
    at org.jboss.weld.context.beanstore.AttributeBeanStore.lock(AttributeBeanStore.java:219)
    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:97)
    at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:64)
    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:93)
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
    at org.omnifaces.cdi.viewscope.ViewScopeManager$Proxy$_$$_WeldClientProxy.preDestroyView(Unknown Source)
    at org.omnifaces.application.ViewScopeEventListener.processEvent(ViewScopeEventListener.java:56)
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)

此页面与其他页面之间的唯一区别是此页面使用 ViewScoped Bean,但我不明白这怎么会成为问题。解决方案?谢谢

最佳答案

你试过这个吗?

String path = FacesContext.getCurrentInstance().getExternalContext().getApplicationContextPath() + "/index.xhtml";
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
FacesContext.getCurrentInstance().getExternalContext().redirect(path);

这对我有用......

关于使用 ViewScoped bean 注销 JSF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21310935/

相关文章:

jsf - 如何在一个 EAR 中的两个 WAR 中使用 OmniFaces 1.6?

date - 如何解决 h :inputText with Date value? 中的 "Conversion Error setting value ' 2013-10-2 6' for ' null Converter'"

css - 如何更改背景颜色工具提示 primefaces 扩展名?

jquery - Primefaces 仅更新选定的选项卡

java - SelectOneMenu 的 Primefaces 3.5 + OmniFaces 1.3 SelectItemsIndexConverter 问题

jsf - 用于 JSF 的服务器端 HTML sanitizer /清理

java - Xpages 脱离服务器端缓存

jsf-2 - ViewScoped bean 的内存泄漏?

java - JSF 2 - 找不到 Ajax 属性

jsf - @ViewScoped在每个回发请求上调用@PostConstruct