DataTable doesnt update filtered values after remove

UI Components for JSF
cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

13 Dec 2012, 16:09

How can we sync it then?

dako-ak
Posts: 60
Joined: 19 Jul 2012, 15:49

13 Dec 2012, 16:29

Hi optimus prime,

i'am not sure what exactly do you mean with your question. But in my opinion, the standard case is that the dataTable should synchronise automatically according to the filters. Maybe the second list for the filtered values is too confusing for a standard case? Or the filtered list should readable only?
PrimeFaces 3.4.2
PrimeFaces-Extensions 0.6.2
Mojarra 2.1.7
JBoss 6.1

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

14 Dec 2012, 09:11

I agree but how to hook-in the point you add-remove objects to actual list, there is no callback unless we create a custom model like FilteredDataModel. In short, there is no easy way if you bind a regular list and another one for filters. If we create a FilteredDataModel that should work I guess, I'll think about it, thanks for the feedback.

bedag-moa
Posts: 3
Joined: 17 Sep 2014, 13:24

23 Oct 2014, 19:53

We don't have to keep the lists in sync at all times, it would be sufficient to have them consistent at rendering time. The easiest approach to do that is to recompute the filtered list whenever the datatable is encoded. If that is deemed to expensive, the datatable could only recompute the filtered list if the source list differs from a snapshot taken when the list was last filtered.

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

24 Oct 2014, 07:59

The lesson here is never maintain a separate list of filtered items. Produce a list of items filtered from the available items on demand.
In future please be more careful changing example code and be certain you know what your code is doing before assuming you have a PrimeFaces issue.

Right, time for me to get out of the bath :)
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

bedag-moa
Posts: 3
Joined: 17 Sep 2014, 13:24

24 Oct 2014, 11:48

Is this adressed to me? We do not maintain a filtered list - the PrimeFaces dataTable does. I agree that it should not cache the filtered list ... at least not if the source list could have changed ...

bedag-moa
Posts: 3
Joined: 17 Sep 2014, 13:24

24 Oct 2014, 15:48

I have partially fixed the bug by subclassing DataTable as follows:

Code: Select all

    @Override
    public void encodeEnd(FacesContext context) throws IOException {
        if (!shouldEncodeFeature(context)) {
            // filter won't be applied (c.f. DataTabelRenderer.encodeEnd())
            if (getFilteredValue() != null) {
                // but should be, in case the source list has changed
                DataTableFeature filterFeature = getFeature(DataTableFeatureKey.FILTER);
                filterFeature.decode(context, this);
                filterFeature.encode(context, new NopRenderer(), this);
            }
        }
        super.encodeEnd(context);
    }

    private static class NopRenderer extends DataTableRenderer {
        @Override
        public void encodeTbody(FacesContext context, DataTable table, boolean dataOnly) throws IOException {
            // do nothing
        }
    }
This will cause PrimeFaces to recompute the filtered list whenever a filtered dataTable is rendered, thereby ensuring that the list not stale when the response is rendered. As the filter conditions are not part of the component state, they are decoded again, which only works if the action source that triggered the request is in the same form as the data table. This could be fixed by keeping the filter values in the component's state.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 56 guests