title: JSF SessionScoped managedBean in conjunction with ViewScoped managedBean
body: <p>I have the following problem in my project:</p>
  
  <p>We have 2 managed beans with the following configuration:</p>
  
  <pre><code>@ManagedBean
  @SessionScoped
  public class SessionBean {
      private PersonnelFile personnelFile; // + getters/setters
  }
  
  @ManagedBean
  @ViewScoped
  public class ViewBean {
      @ManagedProperty("#{sessionBean}")
      private SessionBean sessionBean;
  
      public void selectPersonnel() {
          sessionBean.getPersonnelFile().setPerson(new Person());
      }
  }
  </code></pre>
  
  <p>This is not all of the code, but it gives you a general idea of the sitatution:</p>
  
  <ul>
  <li>SessionScoped bean which holds a session object</li>
  <li>ViewScoped bean which holds view-related objects and a reference to the SessionScoped bean</li>
  </ul>
  
  <p>The problem now is:</p>
  
  <ul>
  <li>I access my view</li>
  <li>I make a few post-backs to the same view, coming back to the view every time.. so far so good</li>
  <li>At a certain moment, I set my session object in the SessionScoped bean with the information from the view and I leave my view... so far so good</li>
  <li>Now, when I return to this view, he creates a new ViewScoped bean instance (as expected) and sets the SessionScoped bean back (because of the ManagedProperty annotation)</li>
  <li>When I debug this, I can see that the reference to the SessionScoped bean remains the same, so it's the same object</li>
  <li>However, the object that I previously set in the SessionScoped bean has become <code>null</code>, meaning he 'lost' the session information about that object</li>
  <li>I never reset this object in the SessionScoped bean, so I don't see where it could have gone wrong...</li>
  </ul>
  
  <p>If you want more explanation or if you want me to phrase this question better, let me know or use the edit button!</p>