title: Primefaces Lazy Filtering Issue
body: <p>I'm attempting to implement lazy loading into my application, but am having issues with my filtering. Sorting is working correctly at this point. With lazy filtering in place the datatable is initially loading the correct count from the table which is 24 records, but it repeats the 1st and 2nd records over and over again. Any help is greatly appreciated.</p>
  
  <p>Here is my ScreenshotListProducer class code:</p>
  
  <pre><code>    @ManagedBean
      @RequestScoped
      public class ScreenshotListProducer implements Serializable  {
         private static final long serialVersionUID = 1L;
         @Inject
         private EntityManager em;
  
         private List&lt;Screenshot&gt; screenshots;
  
         private LazyDataModel&lt;Screenshot&gt; lazyModel = null;
  
         private int pageSize = 5;
  
         public void setPageSize(int pageSize) {
             this.pageSize = pageSize;
         }
  
         public int getPageSize() {
             return pageSize;
         }
  
         @Produces
         @Named
         public List&lt;Screenshot&gt; getScreenshots() {
            System.out.println("************* getting screenshots list **************");
            return screenshots;
         }
  
         @PostConstruct
         public void LoadData() {
           lazyModel = new LazyDataModel&lt;Screenshot&gt;() {
          private static final long serialVersionUID = 1L;
  
        @Override
        public List&lt;Screenshot&gt; load(int first, int pageSize, String sortField, SortOrder sortOrder, Map&lt;String,String&gt; filters) { 
             int start = first;
                    int end = first + pageSize;
                    if (sortField == null) {
                       sortField = "time";
                    }
  
                   try {
                 CriteriaBuilder cb = em.getCriteriaBuilder();
                 CriteriaQuery&lt;Screenshot&gt; criteria = cb.createQuery(Screenshot.class);
                 Root&lt;Screenshot&gt; screenshot = criteria.from(Screenshot.class);
  
                 // sorting
                 if (sortOrder.equals(SortOrder.ASCENDING))
                  {
                    criteria.select(screenshot).orderBy(cb.asc(screenshot.get(sortField)));
                  }
                  else if (sortOrder.equals(SortOrder.DESCENDING))
                  {
                     criteria.select(screenshot).orderBy(cb.desc(screenshot.get(sortField)));
                  }
  
                 // From
                 Root&lt;Screenshot&gt; from = criteria.from(Screenshot.class);
  
                 List&lt;Predicate&gt; predicates = new ArrayList&lt;Predicate&gt;();
  
                 if (filters != null) {
                    // filters
                    for(Iterator&lt;String&gt; it = filters.keySet().iterator(); it.hasNext();) {
                       String filterProperty = it.next(); // table column name = field name
                       System.out.println("filterProperty is: " + filterProperty);
  
                       String filterValue = filters.get(filterProperty);
                       System.out.println("filterValue is: " + filterValue);
  
                       Expression&lt;String&gt; literal = cb.literal((String)filterValue);
                       predicates.add(cb.like(from.&lt;String&gt;get(filterProperty), literal));
                    }
                    criteria.where(predicates.toArray(new Predicate[predicates.size()]));
                 }
  
                 TypedQuery&lt;Screenshot&gt; s = em.createQuery(criteria);
                 s.setMaxResults(end - start);
                 s.setFirstResult(start);
  
                 screenshots = s.getResultList();
  
              } catch (NullPointerException e) {
                 e.printStackTrace();
              }
  
                            return screenshots;
             }
  
           };
  
     lazyModel.setRowCount(24);
     lazyModel.setPageSize(pageSize);
  
     if (lazyModel.getRowIndex() == -1 || lazyModel.getPageSize() == 0) {
              lazyModel.setRowIndex(-1);
         }
         else
             lazyModel.setRowIndex(lazyModel.getRowIndex() % lazyModel.getPageSize());
         }
  
     public LazyDataModel&lt;Screenshot&gt; getLazyModel() {
          return lazyModel;
      }
     }
  </code></pre>
  
  <p>Here is my Screenshot class:</p>
  
  <pre><code>@Entity
  @XmlRootElement
  @Table(name="Test2012", uniqueConstraints = @UniqueConstraint(columnNames = "id"))
  public class Screenshot implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue
      @Column(name = "id", columnDefinition="INT")
      private Long id;
  
      private Timestamp time;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public Timestamp getTime() {
          return time;
      }
  
      public void setTime(Timestamp time) {
          this.time = time;
      }   
  }
  </code></pre>
  
  <p>Here is my xhtml code:</p>
  
  <pre><code>&lt;p:dataTable id="table1" var="scrshot" rowKey="#{scrshot.id}" value="#{screenshotListProducer.lazyModel}" paginator="true" rows="7" paginatorPosition="bottom"
               paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
               rowsPerPageTemplate="7,20,50,100" widgetVar="dataTable" currentPageReportTemplate="(Number of Records: {totalRecords})"
               emptyMessage="No screenshot data found with given criteria" lazy="true" scrollable="true" draggableColumns="true" scrollHeight="217" style="width: 100%;"&gt; 
        &lt;f:facet name="header"&gt; 
        &lt;/f:facet&gt;
        &lt;p:column selectionMode="multiple"/&gt; 
        &lt;p:column id="time" headerText="Time" sortBy="#{scrshot.time}" filterBy="#{scrshot.time}" filterMatchMode="startsWith"&gt; 
          &lt;h:outputText value="#{scrshot.time}"/&gt; 
        &lt;/p:column&gt;   
        &lt;p:column id="id" headerText="ID" sortBy="#{scrshot.id}" filterBy="#{scrshot.id}" filterOptions="#{scrshot.id}" filterMatchMode="exact"&gt; 
          &lt;h:outputText value="#{scrshot.id}"/&gt; 
        &lt;/p:column&gt; 
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <p>Primefaces 3.3.1
  Mojarra 2.1.5
  JBoss AS 7.1.0.Final</p>