JSF 页面元素无法从具有操作属性的支持 bean 触发方法。(JSF2.0 + primefaces)
我有一个带有 menuitem 元素的 primefaces 停靠导航栏,它应该触发我的网络应用程序的注销机制,但它不起作用,我不知道为什么。有人可以帮我找到当我单击菜单项时未调用注销功能的原因吗?
这是 JSF 页面模板中的元素:
<h:form>
<p:dock position="top">
<p:menuitem value="Logout" icon="unsecuredimages/logout.png" action="securityController.logOut()" rendered ="#{!securityController.checkLogged}"/>
</p:dock>
</h:form>
这是 logOut() 方法所在的支持 bean:
@ManagedBean
@RequestScoped
public class SecurityController {
...
public String logOut() {
authentificationEJB.releaseUserState();
return "main.xhtml";
}
...
这是访问会话并将其从登录用户中释放的 EJB:
@Stateful(name = "ejbs/AuthentificationEJB")
public class AuthentificationEJB implements IAuthentificationEJB {
...
// Logout
public void releaseUserState() {
// 1-Check if there is something saved in the session(or wherever the
// state is saved)
if (!FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().isEmpty()) {
// 2-If 1 then flush it
FacesContext.getCurrentInstance().release();
}
}
...
}
当我单击 menuItem 时,我得到这个例外:
警告:StandardWrapperValve[面孔 Servlet]:PWC1406:Servlet.service() 对于 servlet Faces Servlet 抛出 例外 java.lang.IllegalStateException 位于 com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:639) 在 com.sun.faces.context.FacesContextImpl.getCurrentPhaseId(FacesContextImpl.java:515) 在 javax.faces.event.ExceptionQueuedEventContext。(ExceptionQueuedEventContext.java:148) 在 javax.faces.event.ExceptionQueuedEventContext。(ExceptionQueuedEventContext.java:101) 在 com.sun.faces.lifecycle.Phase.queueException(Phase.java:156) 在 com.sun.faces.lifecycle.Phase.queueException(Phase.java:149) 在 com.sun.faces.lifecycle.Phase.doPhase(Phase.java:109) 在 com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 在 javax.faces.webapp.FacesServlet.service(FacesServlet.java:312) 在 org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215) 在 过滤器.RestrictPageFilter.doFilter(RestrictPageFilter.java:90) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188) 在 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641) 在 com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) 在 com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185) 在 org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226) 在 com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165) 在 com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) 在 com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) 在 com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) 在 com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) 在 com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) 在 com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) 在 com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) 在 com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) 在 com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) 在 com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) 在 com.sun.grizzly.ContextTask.run(ContextTask.java:69) 在 com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) 在 com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) 在 java.lang.Thread.run(Thread.java:662)
更新
<p:menuitem value="Logout" icon="unsecuredimages/logout.png" action="#{securityController.logOut}" rendered ="#{!securityController.checkLogged}"/>
@ManagedBean
@ViewScoped
public class SecurityController {
@EJB
private IAuthentificationEJB authentificationEJB;
private String email;
private String password;
private String notificationValue;
public String logOut() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
if (session != null) {
session.invalidate();
}
return "main.xhtml";
}
...
}
I have a primefaces dock nav bar with a menuitem element, that should trigger the logout mechanism of my web app, but it doesnt work, i dont know why. Can someone help me find the reason why the logout funccion is not called when i click on the menu item?
This is the element at the JSF page template:
<h:form>
<p:dock position="top">
<p:menuitem value="Logout" icon="unsecuredimages/logout.png" action="securityController.logOut()" rendered ="#{!securityController.checkLogged}"/>
</p:dock>
</h:form>
This is the backing bean where the logOut() Method is located:
@ManagedBean
@RequestScoped
public class SecurityController {
...
public String logOut() {
authentificationEJB.releaseUserState();
return "main.xhtml";
}
...
And this is the EJB that accesses the session and releases it from the logged user:
@Stateful(name = "ejbs/AuthentificationEJB")
public class AuthentificationEJB implements IAuthentificationEJB {
...
// Logout
public void releaseUserState() {
// 1-Check if there is something saved in the session(or wherever the
// state is saved)
if (!FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().isEmpty()) {
// 2-If 1 then flush it
FacesContext.getCurrentInstance().release();
}
}
...
}
When i click on the menuItem i get this exception:
WARNING: StandardWrapperValve[Faces
Servlet]: PWC1406: Servlet.service()
for servlet Faces Servlet threw
exception
java.lang.IllegalStateException at
com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:639)
at
com.sun.faces.context.FacesContextImpl.getCurrentPhaseId(FacesContextImpl.java:515)
at
javax.faces.event.ExceptionQueuedEventContext.(ExceptionQueuedEventContext.java:148)
at
javax.faces.event.ExceptionQueuedEventContext.(ExceptionQueuedEventContext.java:101)
at
com.sun.faces.lifecycle.Phase.queueException(Phase.java:156)
at
com.sun.faces.lifecycle.Phase.queueException(Phase.java:149)
at
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:109)
at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at
javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at
filters.RestrictPageFilter.doFilter(RestrictPageFilter.java:90)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at
com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at
java.lang.Thread.run(Thread.java:662)
Update
<p:menuitem value="Logout" icon="unsecuredimages/logout.png" action="#{securityController.logOut}" rendered ="#{!securityController.checkLogged}"/>
@ManagedBean
@ViewScoped
public class SecurityController {
@EJB
private IAuthentificationEJB authentificationEJB;
private String email;
private String password;
private String notificationValue;
public String logOut() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
if (session != null) {
session.invalidate();
}
return "main.xhtml";
}
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试从 RequestScoped 更改为会话,我在使用 RequestScoped 支持 bean 的 apst 中遇到了一些麻烦。
Try changing from RequestScoped to for example Sessions, I've had some trouble in the apst with RequestScoped backing beans.
我不知道您是否需要
release()
方法。我认为这个方法是你例外的原因。引用自 javadoc:我使用以下注销方法。也许这对您有帮助:
I don't know if you need the
release()
method. I think this method is the reason for your exception. A quote from the javadoc:I use the following logout method. Maybe this is helpful for you: