title: p:dataTable selections are lost after paginating a LazyDataModel
body: <p>My problem is that after I've selected a few items on the 1st page, if I paginate to another page and come back, my initial selections are not shown. I've tried to implement the <code>SelectableDataModel</code> as well as using the <code>rowKey</code> attribute but the problem persists.</p>
  
  <p>This is my test bean:</p>
  
  <pre><code>@ManagedBean
  @ViewScoped
  public class MrBean {
      private List&lt;Item&gt; chosenItems;
      private LazyDataModel lazyModel;
  
      @PostConstruct
      public void prepareTest() {
          this.lazyModel = new LazyItemDataModel();
      }
  
      public void countItems() {
          System.out.println("TEST 3: chosenItems's size: " + chosenItems.size());
      }
  
      private class LazyItemDataModel extends LazyDataModel&lt;Item&gt; implements SelectableDataModel&lt;Item&gt; {
          @Override
          public Item getRowData(String rowKey) {
              System.out.println("TEST 1: getRowData");
              Iterator&lt;Item&gt; iter = ((List&lt;Item&gt;) this.getWrappedData()).iterator();
              while (iter.hasNext()) {
                  Item item = iter.next();
                  if (item.getId().equals(rowKey)) {
                      return item;
                  }
              }
  
              return null;
          }
  
          @Override
          public Object getRowKey(Item item) {
              return item.getId();
          }
  
          @Override
          public List&lt;Item&gt; load(int first, int pageSize, String sortField, SortOrder sortOrder, Map filters) {
              System.out.println("TEST 2: load");
              // Code to retrieve items from database
          }
      }
  
      // Getters and Setters
  }
  </code></pre>
  
  <p>This is my test page:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"&gt;
      &lt;h:head&gt;
          &lt;title&gt;Test page&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;h:form&gt;
              &lt;p:dataTable id="itemTable" var="item" value="#{mrBean.items}" rows="5" 
                           paginator="true" selection="#{mrBean.chosenItems}" lazy="true" &gt;
  
                  &lt;p:ajax event="rowSelectCheckbox" listener="mrBean.countItems" /&gt;                    
  
                  &lt;p:column selectionMode="multiple" /&gt;
  
                  &lt;p:column headerText="ID"&gt;
                      &lt;h:outputText value="#{item.id}" /&gt; 
                  &lt;/p:column&gt;
  
                  &lt;p:column headerText="Name"&gt;
                      &lt;h:outputText value="#{item.name}" /&gt; 
                  &lt;/p:column&gt;
  
              &lt;/p:dataTable&gt;
          &lt;/h:form&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'd be very grateful if you could show me what I've done wrong here.</p>
  
  <p><strong>UPDATE:</strong> After I added more <code>System.out.println("TEST")</code> to the above code, I observed the following things:</p>
  
  <ol>
  <li>On the console, every time I paginate, <code>TEST 1: getRowData</code> is always printed before <code>TEST 2: load</code>. As a consequence, I believe the method <code>#LazyDataModel.getWrappedData()</code> may return data from the old page. At first, I thought this method's goal was to retrieve the selected rows to highlight on the table. However, if this method is called before <code>load</code>, there's no way it can do the job right?</li>
  <li>After I selected the 1st 2 items on the 1st page, on the console, I saw <code>TEST 3: chosenItems's size: 2</code>. If I paginate to the 2nd page and then back to the 1st page, the selections are lost as mentioned. However, if I continued to select another item, on the console, I saw <code>TEST 3: chosenItems's size: 3</code>. Obviously, the <code>chosenItems</code> list still kept my old selections but they're not rendered on the table.</li>
  </ol>