在我的应用程序中,我有一个顶部栏,其中有一个调用 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/