0

I have this datatable which I implemented with Primefaces's LazyDataModel. Everything works fine except for the initial load when I open the page for the first time or refresh. The load method get called 6-7 times.

When I change page, filter or sort it works correctly, load is only called once.

Since I perform calls to the database I would like to prevent it to be called more then needed.

I have the following:

XHTML:

    <p:outputPanel id="documentsPanel">
        <h:form id="documentsForm">
            <p:dataTable id="documentsTable"
                         widgetVar="documentsTable"
                         var="doc"
                         value="#{MyManagedBean.model}"
                         paginator="true" rows="20"
                         paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}"
                         currentPageReportTemplate="{totalRecords} #{c.NumberOfRequestFound}"
                         lazy="true">
     ...

            </p:dataTable>
        </h:form>
    </p:outputPanel>

Java:

public class DocumentEncodingDataModel extends LazyDataModel<SelectableDocumentToBeEncodedDTO> {

@Override
public List<SelectableDocumentToBeEncodedDTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
   ....
}

@Override
public int getRowCount() {
    return super.getRowCount();
}

@Override
public SelectableDocumentToBeEncodedDTO getRowData(String rowKey) {
    log.debug("getRowData");
    if (!StringUtils.isBlank(rowKey)) {
        for (SelectableDocumentToBeEncodedDTO doc : currentDocumentsToBeEncoded) {
            if (doc.getDocumentToBeEncoded().getId().toString().equals(rowKey)) {
                return doc;
            }
        }
    }
    return null;
}

@Override
public Object getRowKey(SelectableDocumentToBeEncodedDTO doc) {
    return doc.getDocumentToBeEncoded().getId();
}

}

Primefaces version: 6.2 JSF version: 2.1

Ayoub Rossi
  • 410
  • 5
  • 18
  • Could you post the relevant code of MyManagedBean? All references to the `model` field – areus Apr 16 '20 at 15:12
  • 1
    Post the code in [mcve] flavour, and also post PrimeFaces version info... And JSF implementation and version. – Kukeltje Apr 16 '20 at 15:33
  • I added versions. I checked all model references in MyManagedBean but it still happens. My error is probably in the XHTML. Is that possible? – Ayoub Rossi Apr 16 '20 at 18:47
  • encodeEnd method in class DataTable renderer from package org.primefaces.component.datatable is called multiple times which causes the load multiple times – Ayoub Rossi Apr 16 '20 at 18:50
  • That is why a [mcve] is requested. – Kukeltje Apr 16 '20 at 18:51

0 Answers0