webtier@glassfish.java.net

Correct way to terminate a session / JSF 2 ?

From: <webtier_at_javadesktop.org>
Date: Mon, 22 Mar 2010 16:20:17 PDT

When logging out of an application, I wanted to remove the session associated with the user. To do this I ended up with the following:

<h:commandLink action="#{logoutBean.testAction}" value="#{menu.FILE_EXIT}" />
...
public String testAction()
{
   FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
   return "/login.xhtml";
}

This has the desired effect in destroying the session and returning to the login page, but I generate an exception in the background:

SEVERE: javax.faces.FacesException: No active contexts for scope type javax.context.RequestScoped
javax.faces.FacesException: No active contexts for scope type javax.context.RequestScoped
        at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:136)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:115)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:135)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:309)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
        at java.lang.Thread.run(Thread.java:619)

Two questions:

1. Is this the correct approach ?, if not, what do you recommend ?
2. If yes, how do I deal with the exception
[Message sent by forum member 'softwaresimian']

http://forums.java.net/jive/thread.jspa?messageID=393200