DataTable doesnt update filtered values after remove
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
How can we sync it then?
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?
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
PrimeFaces-Extensions 0.6.2
Mojarra 2.1.7
JBoss 6.1
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
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.
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.
- andyba
- Expert Member
- Posts: 2473
- Joined: 31 Mar 2011, 16:27
- Location: Steinfeld, near Bremen/Osnabrück, DE
- Contact:
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
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
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now
I have partially fixed the bug by subclassing DataTable as follows:
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.
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
}
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 56 guests