Why does the primefaces dataScroller stop fetching records?

Asked

Viewed 202 times

0

My xhtml is 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 I 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 the DAO the method is 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-3, the first time he brings 3, when he gives the scroll bar, he brings 3 more and then he stops to go get more records. Being that I have much more than 6 records in the bank.

I don’t know if I’m doing it right or wrong, so I wanted your help, I want him to bring all the bank records, but going 3 by 3

1 answer

0

It is necessary to provide the total of results to be paged for the LazyDataModel.

As found in the 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 total results and set that total to totalRowCount of LazyDataModel. Something like:

// ...
int totalRegistrosDiarios = RegistroDiarioDAO.getTotalLastRegistrosDiariosVelhos();
registros.setRowCount(totalRegistrosDiarios);
// ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.