dataTable: sort fails until filter used then ok

UI Components for JSF
Post Reply
webel
Posts: 87
Joined: 18 Sep 2010, 09:29
Location: Sydney, Australia
Contact:

06 Sep 2011, 05:01

Primefaces 2.2.1

I looked carefully through issues/forum but did not find similar report.

I have multiple columns and use sortBy on all and filterBy on only one.
On fresh page load sortBy does not work, clicking on header is ignored.
However, if I enter a character into the filter, thereafter sorting works.

The exact same problem was reported by somebody else here:
http://stackoverflow.com/questions/5487 ... 69#6888769

This happens with data pulled from database by query, with reset per page load using:

Code: Select all

        <f:view>
            <f:metadata>
                <f:event type="preRenderView" listener="#{electricalEnergyConsumerManager.reset}"/>
            </f:metadata>
        </f:view>
Where reset forces reloading of consumerBlocks used as dataTable rows:

Code: Select all

    public void reset() {
        consumerBlocks = null;
..
    }
The dataTable uses consumerBlocks as rows and (at least) one filter thus:

Code: Select all

                <p:dataTable 
                    value="#{electricalEnergyConsumerManager.consumerBlocks}" 
                    var="consumer"
                    rowEditListener="#{electricalEnergyConsumerManager.updateConsumerRow}"
                    >
                    <p:column styleClass="view-field-name" sortBy="#{consumer.name}" filterBy="#{consumer.name}">
                        <f:facet name="header">
                            Electrical energy consumer
                        </f:facet>
                        <p:cellEditor>
                            <f:facet name="output">
                                <util:view_link element="#{consumer}"/>
                            </f:facet>
                            <f:facet name="input">
                                <h:inputText value="#{consumer.name}"/>
                            </f:facet>
                        </p:cellEditor>                        
                    </p:column>
The consumerBlocks are only pulled from a database query via the getter when null (just after reset in page load):

Code: Select all

    private List<Block> consumerBlocks;

    public List<Block> getConsumerBlocks() {
        if (consumerBlocks == null) {
            consumerBlocks = fetchConsumerBlocks();
        }
        return consumerBlocks;
    }

    public List<Block> fetchConsumerBlocks() {
        if (projectManager.getProject() == null) {
            return null;//TODO warn
        }
        return blockQuery.findElectricalEnergyConsumerBlocks(projectManager.getProject());
    }
Where the actual database query is performed via an injected session bean blockQuery.

This strategy ensures do not repeat query for each JSF phase through multiple getter calls.

I had written:
If I remove the filterBy the sorting works fine ..

EDITED: this is not so, the filterBy has to be there for the sorting to work at all in my case.
Primefaces 6.1
JSF Mojarra 2.3.0
(Netbeans 8.2+Glassfish 4.1.1 OR Payara 4.1)
Mac OS X "Yosemite" 10.10.5 / Linux CentOS 6.7

webel
Posts: 87
Joined: 18 Sep 2010, 09:29
Location: Sydney, Australia
Contact:

09 Sep 2011, 04:21

Primefaces 6.1
JSF Mojarra 2.3.0
(Netbeans 8.2+Glassfish 4.1.1 OR Payara 4.1)
Mac OS X "Yosemite" 10.10.5 / Linux CentOS 6.7

webel
Posts: 87
Joined: 18 Sep 2010, 09:29
Location: Sydney, Australia
Contact:

08 Apr 2013, 03:47

Update: Primefaces 3.5 seems to have fixed this p:dataTable sortBy problem that I reported on 2.2.1 and was still a problem on 3.3.

However, on Mac OS X, p:dataTable only works correctly on some Firefox versions on some Max OS X versions.

It is OK on Firefox 20.0 on Mac OS X 10.6.8 (both still supported).

There are a number of very strange problems on Firefox 16.0.2 (which is end of line) on Mac OS X 10.5.8 (also end of line), such as the edit icons appearing as pen, tick, cross and row editing not activating at all, the sort icon not appearing, and on sorting the column headers explode and are repeated strangely offset to the right of all column headers. Row-editing worked fine with Primefaces 3.3 on Firefox 16.0.2 (which is end of line) on Mac OS X 10.5.8.

On Mac OS X 10.5.8 row editing and sortBy are both ok on Safari 5.0.6 and also Chrome 21.0.1180.90.

These tests were performed on Glassfish 3.1.1 (in Netbeans7.1).
Primefaces 3.3
Primefaces 6.1
JSF Mojarra 2.3.0
(Netbeans 8.2+Glassfish 4.1.1 OR Payara 4.1)
Mac OS X "Yosemite" 10.10.5 / Linux CentOS 6.7

webel
Posts: 87
Joined: 18 Sep 2010, 09:29
Location: Sydney, Australia
Contact:

14 Apr 2013, 13:55

Major EDIT after further tests with the provided sample problem:

My system is:

Primefaces 3.5 (upgraded from Primefaces 3.3)
latest Mac OS X (Mountain Lion) 10.8.3
Glassfish 3.1.1
Mojarra 2.1.3 (FCS b02)

I tested sample problem previously provided at http://primefaces.googlecode.com/issues ... 5939773395

The problem described still happens in the sample problem (as provided) for both of these browsers

Firefox 16.0.2
Safari 6.0.3

I have tried the SampleController @ManagedBean with both @SessionScoped and @ViewScoped.

I can get the provided sample problem to sort properly (without the filterBy trick) if I do the following.

1. I introduce a lazy holder for the Sample items, and use a simple List of Sample items in SampleController:

Code: Select all

    /**
     * Webel
     */
    public void reset() {
        //items = null;
        sampleList = null;
    }

    /**
     * Webel
     */
    private List<Sample> sampleList;
            
    /**
     * Webel
     */
    public List<Sample> getSampleList() {
        if (sampleList == null) {
            sampleList = getAllSample();
        }
        return sampleList;
    }

    /**
     * Original
     * 
     * @return 
     */
    public List<Sample> getAllSample() {
        return ejbFacade.findAll();
    }
In the index.xhtml with the p:dataTable sortBy tests, I introduce this reset:

Code: Select all

        <!-- Webel -->
        <f:view>
            <f:metadata>
                <f:event type="preRenderView" listener="#{sampleController.reset()}"/>
            </f:metadata>
        </f:view> 
And in the p:dataTable I do not use the getAllSample() fetch fro database directly, which repopulates the entire time, I use the lazy getSampleList():

Code: Select all

           
            <!-- ORIGINAL
            <p:dataTable var="item" value="#{sampleController.allSample}">
            -->
            <!-- Webel -->
            <p:dataTable var="item" value="#{sampleController.sampleList}">
 
I appreciate fully that this approach has been recommended already by the Primefaces team here and elsewhere, and I use this approach in many circumstances in my complex real application. It was not working ok for me with Primefaces 3.3, it is working ok for Primefaces 3.5.

However, I am still having sortyBy problems in many cases where, for example, I populate the p:dataTable with a derived list computed as a @Transient list by a rich entity, but I need to isolate those in a suitable test case.
Last edited by webel on 15 Apr 2013, 03:52, edited 1 time in total.

webel
Posts: 87
Joined: 18 Sep 2010, 09:29
Location: Sydney, Australia
Contact:

14 Apr 2013, 14:06

Further test results, also with:

Primefaces3.5
Mac OS X (Mountain Lion) 10.8.3
Glassfish 3.1.1
Mojarra 2.1.3 (FCS b02)
Firefox 16.0.2
Safari 6.0.3

In a very complex system (I need to isolate a test case that demonstrates this) I am finding that the filterBy trick is needed to get sortBy working when I use p:dataTable within a composite component, but for some reason it works outside a composite component for my @ViewScoped case, where the value list of the dataTable is lazy loaded once per view scope.

EDIT: 2013-04-15 I investigated the problem further with an isolated test case and the problem was not the use of p:dataTable inside a composite component, it was because I was feeding a derived @Transient list into the composite to populate the p:dataTable. I still don't understand why it does not work, because I am lazy loading correctly per @ViewScoped the rich entity that computes the derived list.
Primefaces 6.1
JSF Mojarra 2.3.0
(Netbeans 8.2+Glassfish 4.1.1 OR Payara 4.1)
Mac OS X "Yosemite" 10.10.5 / Linux CentOS 6.7

webel
Posts: 87
Joined: 18 Sep 2010, 09:29
Location: Sydney, Australia
Contact:

22 Apr 2013, 09:17

There is a detailed new discussion of related problems with a new Sample entity p:dataTable test suite here:

p:dataTable: test suite: sorting with many tables per view

Multiple new issue reports and feature requests corresponding to the problems described there will be progressively made referencing it and the Sample dataTable test suite presented there.

Please do not further discuss this matter in this forum posting here, it is now obsolete.
Primefaces 6.1
JSF Mojarra 2.3.0
(Netbeans 8.2+Glassfish 4.1.1 OR Payara 4.1)
Mac OS X "Yosemite" 10.10.5 / Linux CentOS 6.7

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 58 guests