I want to include pagination and row toggling in my primefaces datatable, but with every click (other page / toggle) everything gets reloaded again. How could I solve this?
Backingbean:
import java.io.Serializable;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import be.fgov.health.ecad.domain.request.PendingRequest;
import be.fgov.health.ecad.service.RequestService;
@Named
@SessionScoped
public class RequestBean implements Serializable {
private static final long serialVersionUID = -6538980904680369808L;
@Inject
private RequestService requestService;
private List<PendingRequest> pendingRequests;
public void init() {
pendingRequests = requestService.findAllPendingRequests();
}
public List<PendingRequest> getPendingRequests() {
return pendingRequests;
}
xhtml page:
<f:event listener="#{requestBean.init}" type="preRenderView" />
<p:dataTable id="pendingRequests" var="pendingRequest"
value="#{requestBean.pendingRequests}" reflow="true" rows="5" paginator="true" resizableColumns="true" rowsPerPageTemplate="5,10,20,50">
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Request reference" filterBy="#{pendingRequest.requestReference}" filterMatchMode="contains">
<h:outputText value="#{pendingRequest.requestReference}" />
</p:column>
<p:rowExpansion>
<p:dataTable var="pendingRequestDocument"
value="#{pendingRequest.pendingRequestDocuments}">
<p:column headerText="Stored document">
<h:outputText value="#{pendingRequestDocument.storedDocument}" />
</p:column>
</p:dataTable>
</p:rowExpansion>
</p:dataTable>
I can't really figure out what I'm doing wrong. The documents are eagerly loaded with JPA..
The query behind the init method (preRenderView) gets executed again after any action with that datatable.
JSF: 2.0 Primefaces: 5.2