title: Access and modify property(ies) of an Application-Scoped Managed Bean from Session Listener
body: <p>I need to access an application-scoped managed bean to modify certain properties from within an HttpSessionListener.</p>
  
  <p>I already used something like the following:</p>
  
  <pre><code>@Override
  public void sessionDestroyed(HttpSessionEvent se) {
      HttpSession session = se.getSession();
      User user = userService.findBySessionId(session.getId());    
  
      ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
  
       ApplicationScopedBean appBean = (ApplicationScopedBean) externalContext.getApplicationMap().get("appBean");
  
       appBean.getConnectedUsers().remove(user);
  }
  </code></pre>
  
  <p>externalContext = FacesContext.getCurrentInstance().getExternalContext() causes a null pointer exception here already, and even if it didn't I'm not sure appBean could be accessible the above way.</p>
  
  <p>Any ideas?</p>