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";
}
...
}