0
votes

I have method calls included for custom sorting of Strings and numeric types in my Primefaces datatable component. The non-lazy datatables' sortings are working perfectly well in the current situation. But when I switch to lazy-loading, the custom sorting methods aren't called (debugged correctly) although I have the needed load implementation and I can lazy load my data with no flaws. Since my own methods are not being called, sorting errors do occur with PF's own sorting mechanisms. It sorts the data but having troubles with foreign characters of our alphabet, also the numerics are treated like Strings etc.

The question is: How can I make my own sort functions called properly with lazy-loading?

I'm using Primefaces 5.0, JSF 2.2 Mojarra, JDK 1.7, WebLogic server

p.s: off-topic attributes (filters etc.) are omitted.

<p:dataTable id="resourceDataTable" var="result" widgetVar="someWidgetVar"
         value="#{someBean.someDataModel.lazyModel}" paginator="true" rowKey="#{result.id}"
         rowsPerPageTemplate="5,10,15" rows="5" styleClass="incidentDatatableClass"
         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
         currentPageReportTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
         lazy="true" rowSelectMode="checkbox">

        <p:column width="7">
            <p:selectBooleanCheckbox id="resourceCheckbox" value="#{result.selected}" style="margin-top: 4px;">
                <p:ajax listener="#{copResourceBean.resourceDataModel.selectionChanged(result)}" update=":resourceForm:selectedResourcePanel"/>
            </p:selectBooleanCheckbox>
        </p:column>

        <p:column id="resourceName" headerText="#{language['someHeader']}" sortBy="#{result.name}" 
                  sortFunction="#{helper.sortString}">
            <h:outputText value="#{result.name}" />
        </p:column>

        <p:column id="facilityName"  sortBy="#{result.facilityName}" sortFunction="#{helper.sortString}" headerText="#{language['someHeader']}" >
            <h:outputText value="#{result.facilityName}" />
        </p:column>

        <p:column id="availableQuantity" headerText="#{language['someHeader']}" width="80" sortBy="#{result.availableQuantity}" 
                  sortFunction="#{helper.sortNumeric}" >
            <h:outputText value="#{result.availableQuantity}" />
        </p:column>
    </p:dataTable>
1
That is as expected. With lazy loading you need to do the sorting IN the load method of your LazyDataModel - Kukeltje
yes. as it was clearly stated in pg. 161 :) I missed the solution by 8 minutes because I was lazy-loading the needed data! (ew. ok, that was bad) can you post it as a response so that we can tell the world the problem is solved?primefaces.org/docs/guide/primefaces_user_guide_5_0.pdf - patateskafa

1 Answers

3
votes

The custom sort (or filter functions/methods) do not work when using lazy loading, nor are they intended to. In the case of lazy loading, you should implement the sorting/filtering in the load method of the LazyDatamodel implementation.