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