简体   繁体   中英

How to get the pagenumber in a lazy loading data table

I have a lazy loaded data table and I want to pass page number or rows count from the XHTML to the ManagedBean. How can I do it?This is the data table that I am using:

<p:dataTable var="studyPlanList" value="#{editBean.lazyModel}"
        paginator="true" rows="5"
        paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
        rowsPerPageTemplate="5,10,15" selectionMode="single"
        selection="#{editBean.selectedStudyPlan}" id="studyPlanTable">
        <p:ajax event="rowSelect" listener="#{editBean.onRowSelect}"
            update=":studyPlanEditForm :relatedFileEditForm" />
        <p:column headerText="StudyPlan" sortBy="#{studyPlanList.name}"
            filterBy="#{studyPlanList.name}" width="100">
            <h:outputText value="#{studyPlanList.name}" />
        </p:column>
        <p:column headerText="StudyPlan Status" width="100">
            <h:graphicImage
                value="#{editBean.statusKeyMap.get(studyPlanList.status)}"
                style="float:center;height: 18px;width: 20px"
                title="#{editBean.statusTitleMap.get(studyPlanList.status)}" />
        </p:column>
        <p:column headerText="Messages" width="100">
            <ui:fragment rendered="#{studyPlanList.status eq 300}">
                <h:outputText style="font: italic;"
                    value="Please click Finish Editing to Finish SpokenTutorial" />
            </ui:fragment>
        </p:column>
    </p:dataTable>

If you use LazyLoading, then in your bean you have an implementation of LazyDataModel, and you are overriding method load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) . You are supposed to load collection from database from inside this method, and here you have the page size, and the first record to retrieve (page number would be first / pageSize )

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