title: Injected Session Scoped Bean in View Scoped bean duplicating
body: <p>I have a <code>ViewScoped</code> bean and in this bean I am injecting a <code>SessionScoped</code> bean.  A lot of information is found on this and is pretty straight forward.</p>
  <p><strong>Session bean</strong></p>
  <pre><code>import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.HashMap;
  
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  
  @ManagedBean
  @SessionScoped
  public class Following implements Serializable {
      private HashMap&lt;Integer, ArrayList&lt;String&gt;&gt; followingThese;
  
      //Constructors and getters+setters
      ...
  }
  </code></pre>
  <p><strong>View Bean</strong></p>
  <pre><code>import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Map.Entry;
  import java.util.ResourceBundle;
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  import javax.faces.application.FacesMessage;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.ManagedProperty;
  import javax.faces.bean.ViewScoped;
  import javax.faces.component.UICommand;
  import javax.faces.context.FacesContext;
  import javax.faces.event.ActionEvent;
  
  @ManagedBean
  @ViewScoped
  public class DisplayResults implements Serializable {
  
      // Following Bean
      @ManagedProperty(value = &quot;#{following}&quot;)
      private Following followingBean;
  
      // other information...
      ...
  
      //*and this is how this injected bean is used*
      public void startStopFollowing(int id, name) {
           followingBean.startStopFollowing(id, name);  //adds this id to followingThese
      }
  }
  </code></pre>
  <p><strong>Facelet</strong></p>
  <pre><code>...
  &lt;h:outputText value=&quot;#{displayResults.followingBean.followingThese}&quot; id=&quot;test&quot;/&gt;
  &lt;h:outputText value=&quot;#{following.followingThese}&quot; id=&quot;test2&quot;/&gt;
  
  ...
  
  &lt;h:selectBooleanCheckbox value=&quot;#{results.followed}&quot; immediate=&quot;true&quot; 
      valueChangeListener=&quot;#{displayResults.startStopFollowing(displayResults.id, displayResults.name)}&quot;&gt;
       &lt;f:ajax render=&quot;:test :test2&quot;/&gt;
  &lt;/h:selectBooleanCheckbox&gt;
  </code></pre>
  <p>The interesting thing here is that <code>test</code> gets updated by clicking the checkbox but <code>test2</code> doesn't.  The session scoped variables never get updated.  When refreshing the page, I loose all the info I had in <code>#{displayResults.followingBean.followingThese}</code></p>
  <p><em><strong>Edit</strong></em> : The session variable doesn't get updated on an ajax call only the &quot;injected session variable&quot;</p>
  <p>If I change <code>javax.faces.STATE_SAVING_METHOD</code> to <code>server</code> this code above works, but when on <code>client</code>, nothing.  I lose all my &quot;session&quot; information that has been saved through the <code>ViewScoped</code> bean.</p>
  <p><em><strong>Edit</strong></em>
  Forgot to mention.  Using JSF (Majorra) 2.1.6 on Glassfish 3.1.2.2  (just updated everything hoping that this might solve an issue).</p>
  <p><em><strong>Edit #2</strong></em>
  Added full list of imports with code above.</p>
  <p><em><strong>Added information</strong></em>
  After trying a few things here and there, the functionalities I am looking for work no problem if I set the receiving bean to a <code>RequestScoped</code> OR <code>SessionScoped</code>.  It doesn't work when set to <code>ViewScoped</code>.  This would be all nice and dandy, but I need other functionalities I need from the view scope and this would make no sense to set my bean to session scope.</p>
  <p>Any help is appreciated.</p>
  <h3>Edit 3</h3>
  <p>This has been logged as a bug on <a href="http://java.net/jira/browse/JAVASERVERFACES-1950?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel" rel="nofollow noreferrer">JIRA</a></p>