primefaces: DataTable: Global FilterFunction Broken
Describe the defect Working on a showcase example to put back the old GlobalFilterFunction and the functionality has changed.
<p:dataTable var="customer" value="#{dtFilterView.customers2}" widgetVar="customersTable2"
emptyMessage="No customers found with given criteria"
filteredValue="#{dtFilterView.filteredCustomers2}" filterBy="#{dtFilterView.filterBy}"
globalFilterFunction="#{dtFilterView.globalFilterFunction}">
<f:facet name="header">
<div class="p-text-left">
<h:outputText value="Search all fields using globalFilterFunction:" />
<p:inputText id="globalFilter" onkeyup="PF('customersTable2').filter()" style="width:150px"
placeholder="Enter keyword" />
</div>
</f:facet>
public boolean globalFilterFunction(Object value, Object filter, Locale locale) {
String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase();
if (LangUtils.isValueBlank(filterText)) {
return true;
}
int filterInt = getInteger(filterText);
Customer customer = (Customer) value;
return customer.getName().toLowerCase().contains(filterText)
|| customer.getCountry().getName().toLowerCase().contains(filterText)
|| customer.getRepresentative().getName().toLowerCase().contains(filterText)
|| customer.getStatus().name().toLowerCase().contains(filterText)
|| customer.getActivity() < filterInt;
}
its expecting the value
to be the Customer POJO and right now it is just passing it each individual column value as a String which causes java.lang.ClassCastException: java.lang.String cannot be cast to org.primefaces.showcase.domain.Customer
.
The old code was passing the table.RowData();
if (hasGlobalFilter && globalFilterFunction != null) {
globalMatch = (Boolean) globalFilterFunction.invoke(elContext, new Object[]{table.getRowData(), globalFilterValue, filterLocale});
}
But the new code is passing each individual column.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- Fix #6953: DataTable global filterFunction — committed to melloware/primefaces by melloware 3 years ago
- Fix #6953: DataTable global filterFunction — committed to melloware/primefaces by melloware 3 years ago
- Fix #6953: DataTable global filterFunction (#6954) — committed to primefaces/primefaces by melloware 3 years ago
- Fix #6953: Remove dead code — committed to melloware/primefaces by melloware 3 years ago
- Fix #6953: Remove dead code — committed to melloware/primefaces by melloware 3 years ago
- Fix #6953: Refactor globalFilter — committed to melloware/primefaces by melloware 3 years ago
- Fix #6953: Refactor globalFilter — committed to melloware/primefaces by melloware 3 years ago
- Fix #6953: Refactor globalFilter — committed to melloware/primefaces by melloware 3 years ago
Integration Tests…
Global Filter: https://github.com/primefaces-extensions/primefaces-integration-tests/commit/64d6e5c246ab3735889142a77060e8d3ec6f4451
Global Filter Function: https://github.com/primefaces-extensions/primefaces-integration-tests/commit/18d79fca8a43d45aee64bdc0547c90ab4cec3dee
@melloware @sqores please dont merge such PRs without review before. We must at least clarify what should be the correct behavior and refactor the code for it, not just hackin this behavior, without removing the old behavior.