Why does the dataScroller of primefaces stop fetching the records?

0

My xhtml looks like this:

<p:dataScroller  ajax="true" id="listaDiarios" 
    chunkSize="3"  lazy="true"
    value="#{managedBeanUsuario.lazyRegistrosDiarios}"
    columnClasses="first-letter-page-diary,second-letter-page-diary"
    var="registro">

The load did as follows:

    LazyDataModel registros = new LazyDataModel() {

    private static final long serialVersionUID = -4742720028771554420L;
       @Override
       public List<RegistroDiario> load(int first, int pageSize,
          String sortField, SortOrder sortOrder,
          Map<String, Object> filters) {
          // TODO Auto-generated method stub
          System.out.println("entrei load "+ first);
          System.out.println("entrei size "+ pageSize); 
          System.out.println("qnt linhas "+ this.getRowCount()); 

          return RegistroDiarioDao.getAllLastRegistroDiarioVelho(first);

   }
};

And in DAO the method looks like this:

 public static ArrayList getAllLastRegistroDiarioVelho(int inicio) {

     EntityManager em = HibernateManageFactory.getFactory() 
        .createEntityManager();

     Query query = em.createQuery(
        "select u from RegistroDiario u order by u.dtRegistro desc",
        RegistroDiario.class);
query.setMaxResults(3); 
query.setFirstResult(inicio);
@SuppressWarnings("unchecked")

ArrayList<RegistroDiario> registrosDiarios = (ArrayList<RegistroDiario>) query.getResultList();

em.close();
return registrosDiarios;
}

He brings the records, so far so good. I want him to always bring 3 in 3, the first time he brings 3, when he gives the scroll bar, he brings 3 more and then he stops fetching more records. Being that I have much more than 6 records in the bank.

I do not know if I'm doing it right or wrong, so I wanted your help, I want it to bring all the records from the bank,     

asked by anonymous 28.11.2015 / 21:52

1 answer

0

You must provide the total results to be paginated to LazyDataModel .

As found in version 3.5 documentation:

  

In addition to load method, totalRowCount needs to be provided so that paginator can display itself   according to the logical number of rows to display.

Run a query that counts the total results and set this total to totalRowCount of LazyDataModel . Something like:

// ...
int totalRegistrosDiarios = RegistroDiarioDAO.getTotalLastRegistrosDiariosVelhos();
registros.setRowCount(totalRegistrosDiarios);
// ...
    
28.11.2015 / 22:38