使用数据库对lazy primefaces数据进行排序

时间:2017-05-24 06:56:43

标签: primefaces lazy-loading pf-datatable

我有大量的记录,所以我使用primefaces lazyloading从数据库和显示中获取记录,我已经实现了lazyDataModel的加载方法,并且分页正在工作,但是在排序时它无法正确排序,我的代码是如下:

LazyDataModel<StaffMsgingFltDisplayBean> defaultFlightProcesses = new LazyDataModel<StaffMsgingFltDisplayBean>() {

            @Override
            public List<StaffMsgingFltDisplayBean> load(int first, int pageSize,
                    String sortField, SortOrder sortOrder, Map<String, String> filters) {
                List<CnsFlightProcess> defaultFlightProcessLazyList = null;
                List<StaffMsgingFltDisplayBean> displayBeans = null;
                try
                {
                  defaultFlightProcessLazyList = oneFlightMessageService.retrieveLast24hrsFlightLazy(first,pageSize,sortField,sortOrder);
                  displayBeans = processFltProcess(defaultFlightProcessLazyList);
                  int totalCount  = oneFlightMessageService.retrieveLast24hrsFlightLazyTotalCount();
                  setRowCount(totalCount);
                }
                catch(CNSDBException e)
                {
                    e.printStackTrace();
                }

                return displayBeans;
            }

我的主要查询代码是:

Session session = this.getHibernateTemplate().getSessionFactory()
            .getCurrentSession();
    Transaction transaction = session.beginTransaction();
    Query query = null;
    //String sortOrderValue="desc";
    if(sortOrder.equals(SortOrder.ASCENDING))
    {
        query = session.getNamedQuery("retrieveLast24HrsFlightsLazyAsc");
    }
    else
    {
        query = session.getNamedQuery("retrieveLast24HrsFlightsLazyDesc");
    }


    query.setFirstResult(first);
    query.setMaxResults(pageSize);

    query.setParameter("fromDate", fromDate);
    query.setParameter("toDate", toDate);

    String sortFieldValue = retrieveSortField(sortField);


    query.setParameter("sortField", sortFieldValue);
    //query.setParameter("sortOrder", sortOrderValue);

    List<CnsFlightProcess> flightProcesses = query.list();
    transaction.commit();

查询是:

<query name="retrieveLast24HrsFlightsLazyDesc">
    <![CDATA[from CnsFlightProcess cfp where (cfp.crtDttime between :fromDate and :toDate) and (cfp.fltProcStatus = 'SENT' or cfp.fltProcStatus = 'PROCESSED') order by :sortField desc ]]>
</query>

<query name="retrieveLast24HrsFlightsLazyAsc">
    <![CDATA[from CnsFlightProcess cfp where (cfp.crtDttime between :fromDate and :toDate) and (cfp.fltProcStatus = 'SENT' or cfp.fltProcStatus = 'PROCESSED') order by :sortField ]]>
</query>

Xhtml代码:

<p:dataTable styleClass="list" var="flight" rowIndexVar="index" paginator="true" paginatorPosition="bottom" lazy="true" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" rows="2"
        rowStyleClass="#{(index % 2) eq 0? 'tablerow' : 'tablerowAlter'}"
        value="#{staffMsgingHandler.flightMessageBean.fltDisplayBeansLazy}"
        width="1100">

        <p:column>
            <f:facet name="header">
                <h:outputText
                            value="#{message['TokenNo']}"></h:outputText>
            </f:facet>
            <h:outputText value="#{flight.flightProcess.reqTokenNbr}"></h:outputText>
        </p:column>
        <p:column sortBy="#{flight.fltNumber}">
            <f:facet name="header">
                <h:outputText
                    value="#{message['FlightNumber']}"></h:outputText>
            </f:facet>
            <h:outputText value="#{flight.fltNumber}"></h:outputText> 
        </p:column>


        <p:column sortBy="#{flight.flightProcess.cnsFlightMstr.fltBpCd}">
            <f:facet name="header">
                <h:outputText
                    value="#{message['FromPoint']}"></h:outputText>
            </f:facet>
            <h:outputText value="#{flight.flightProcess.cnsFlightMstr.fltBpCd}"></h:outputText>
        </p:column>

0 个答案:

没有答案