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

Most upvoted comments

@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.