title: Primefaces datatable select row and scope
body: <p>I use PrimeFaces 3.1 and I have to select one single row in a datatable.
  I used the example in the Primefaces showcase to do it but it works only when my backing bean is in scope session, not in view, and it means that I have to do some extra jobs to remove it when the user come back on this page, what is wrong in my code?
  My controller (in request scope):</p>
  
  <pre><code>@ManagedBean
  @RequestScoped
  public class Ctrlr implements Serializable{
      @ManagedProperty(value = "#{myDataModel}")
      private MyDataModel dataModel;
      ...
      public void onSelectRow() {
      //do something
      }
  }
  </code></pre>
  
  <p>The backingBean (I have to use session scope to have a correct working):</p>
  
  <pre><code>@ManagedBean
  @ViewScoped
  public class MyDataModel extends ListDataModel&lt;Bean&gt; implements SelectableDataModel&lt;Bean&gt;, Serializable {
      ...
  }
  </code></pre>
  
  <p>And my xhtml page:</p>
  
  <pre><code>&lt;p:dataTable var="bean" 
          id="tableResults"
          selectionMode="single"
          selection="#{ctrlr.selectedBean}" 
          value="#{myDataModel}" 
          rowKey="#{bean.id}"&gt;
          &lt;p:ajax event="rowSelect" 
              listener="#{ctrlr.onSelectRow()}"
              update=":searchForm:details:detail"/&gt;
          ...
  </code></pre>
  
  <p>I checked in debug, and it seems that each time the controller is rebuilt (each request), the property injected is a new one, instead of re-injecting the one from the viewScope.</p>
  
  <p>If someone can help me to avoid the usage of the session scope?</p>