简体   繁体   中英

pagination with lazy loading in primefaces donesn't work properly

I am getting a problem with lazy loading in dataTable but couldn't to know where the problem is, here is my xhtml page code:

 <f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Application</title>
</h:head>
<h:body>
    <h:form>
        <h:panelGrid columns="2">
          <h:outputLabel value="Element per page"/>
          <p:selectOneMenu value="#{applicationManagementListBean.pageSize}">
              <f:selectItem itemLabel="5" itemValue="5"/>
              <f:selectItem itemLabel="10" itemValue="10"/>
              <f:selectItem itemLabel="30" itemValue="30"/>
              <f:selectItem itemLabel="50" itemValue="50"/>
              <p:ajax event="change" update="applicationDataList"/>
          </p:selectOneMenu>
        </h:panelGrid>
        <p:commandButton value="New application"
            action="inscription.xhtml?faces-redirect=true" ajax="false" />
        <p:dataTable id="applicationDataList" value="#{applicationManagementListBean.applications}"
            var="app" paginator="true"
            rows="#{applicationManagementListBean.pageSize}" lazy="true"
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">


            <p:column headerText="Code">
                <h:outputText value="#{app.code}" />
            </p:column>

            <p:column headerText="Name">
                <h:outputText value="#{app.name}" />
            </p:column>

            <p:column headerText="Abreviate name">
                <h:outputText value="#{app.abrevName}" />
            </p:column>

            <p:column headerText="Status">
                <h:outputText value="#{app.status.description}" />
            </p:column>


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

</h:body>
     </f:view>

and the bean code:

@ManagedBean
@ViewScoped
public class ApplicationManagementListBean implements Serializable {

    private static final long serialVersionUID = 1L;

    @ManagedProperty(value = "#{applicationManagementService}")
    public ApplicationManagementRemote applicationManagementService;

    private Integer pageSize = 3;
    private DataProxyLazyDataModel data;

    public void setApplicationManagementService(
            ApplicationManagementRemote applicationManagementService) {
        this.applicationManagementService = applicationManagementService;
    }

    public LazyDataModel<Object> getApplications() {
        data = new DataProxyLazyDataModel(applicationManagementService);
        data.setPageSize(pageSize);
        return data;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public DataProxyLazyDataModel getData() {
        return data;
    }

    public void setData(DataProxyLazyDataModel data) {
        this.data = data;
    }

  }

when I click on the next page button nothing happen

please help thanks a lot best regards, Rachid

primegaces 3.4.2, liferay portal 6.1, eclipse

try adding setRowCount() to your lazyDataModel .

for example:

lazyDataModel.setRowCount(rows);

where rows represents total records in your Database to display in DataTable . In your case code is:

data.setRowCount(rows);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM