1

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

GregD
  • 1,884
  • 2
  • 28
  • 55
  • You have a nested datatable. What datatable are you talking about? And what PF Version do you use? And what jsf version? and can you create an mcve? – Kukeltje Apr 16 '15 at 12:42
  • @Kukeltje question is updated. – GregD Apr 16 '15 at 12:46
  • Well, (parts of) your view ARE rendered again when ajax is used… then maybe use a viewscoped bean and do the init in the postconstruct of that bean. And JSF 2.0 is to generic... Mojarra/Myfaces? 2.0.3? etc.. – Kukeltje Apr 16 '15 at 12:49
  • @Kukeltje ViewScoped doesn't exist in the CDI context. – GregD Apr 16 '15 at 12:51
  • 1
    Then use omnifaces... or just do it in the postconstruct of the sessionscoped bean or do what in the 'duplicate' is mentioned... check for 'isPostBack()' – Kukeltje Apr 16 '15 at 12:52
  • You can mark it as a duplicate since the postConstruct solves it. Thanks! – GregD Apr 16 '15 at 12:57

0 Answers0