title: HttpSession - how to get the session.setAttribute?
body: <p>I'm creating HttpSession container this way:</p>
  
  <pre><code>@SessionScoped
  @ManagedBean(name="userManager")
  public class UserManager extends Tools
  {
    /* [private variables] */
    ...
    public String login() 
    {
      /* [find user] */
      ...
      FacesContext context = FacesContext.getCurrentInstance();
      session = (HttpSession) context.getExternalContext().getSession(true);
      session.setAttribute("id", user.getID());
      session.setAttribute("username", user.getName());
      ...
      System.out.println("Session id: " + session.getId());
  </code></pre>
  
  <p>And I have SessionListener which should gives me info about session created: </p>
  
  <pre><code>@WebListener
  public class SessionListener implements HttpSessionListener
  {
    @Override
    public void sessionCreated(HttpSessionEvent event) {    
      HttpSession session = event.getSession();
      System.out.println("Session id: " + session.getId());
      System.out.println("New session: " + session.isNew());
      ...
    }
  }
  </code></pre>
  
  <p>How can I get the <code>username</code> attribute? </p>
  
  <p>If I'm trying it using <code>System.out.println("User name: " + session.getAttribute("username"))</code> it throws <code>java.lang.NullPointerException</code>..</p>