2 Replies Latest reply on May 14, 2008 7:33 AM by victoriaonsnow.viktor.rees.nexgo.de

    SessionId within @Destroy method

    victoriaonsnow.viktor.rees.nexgo.de

      How can I get the sessionId inside of an @Destroy method?


      The following code doesn´t work because FacesContext is null. I believe reason is that there is no client request when the session expires? 


      @Destroy
      @Remove
      public void destroy() 
      {
           FacesContext facesContext = FacesContext.getCurrentInstance();
           ExternalContext externalContext = facesContext.getExternalContext();
           HttpSession session = (HttpSession) externalContext.getSession(true);
           String sessionId = session.getId();
                
           AppData appData = (AppData) Component.getInstance("appData");
           appData.getLoggedInSessions().remove(sessionId);
      
           log.debug("removed: " + sessionId );
      }



      appData.getLoggedInSessions() is an application scoped Map
      of Session information.


      Is there an other way to get access to the sessionId?