Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable: Global FilterFunction Broken #6953

Closed
melloware opened this issue Feb 5, 2021 · 15 comments · Fixed by #6954
Closed

DataTable: Global FilterFunction Broken #6953

melloware opened this issue Feb 5, 2021 · 15 comments · Fixed by #6954
Assignees
Labels
🐞 defect Bug...Something isn't working
Milestone

Comments

@melloware
Copy link
Member

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.

@melloware melloware added the 🐞 defect Bug...Something isn't working label Feb 5, 2021
@Rapster
Copy link
Member

Rapster commented Feb 5, 2021

😢

@melloware melloware self-assigned this Feb 5, 2021
@melloware melloware added this to the 10.0.0-RC2 milestone Feb 5, 2021
@melloware melloware linked a pull request Feb 5, 2021 that will close this issue
@christophs78
Copy link
Contributor

We should add a integration-test for this ... whatever the expected correct behaviour is.

@melloware
Copy link
Member Author

I am waiting to hear back on this review then will write one.

melloware added a commit to melloware/primefaces that referenced this issue Feb 6, 2021
@melloware
Copy link
Member Author

@tandraschko
Copy link
Member

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

@tandraschko
Copy link
Member

tandraschko commented Feb 6, 2021

this just leads to dead and bad code now.

@tandraschko tandraschko reopened this Feb 6, 2021
@melloware
Copy link
Member Author

Thomas this use case was wholesale broken and was missed in the refactor. Feel free to review but I believe the fixes are the correct one and I have integration tests to verify.

@tandraschko
Copy link
Member

thats ok but we have deadcode now as FunctionFilterConstraint is actually unused

@melloware
Copy link
Member Author

Are you sure? FunctionFilterConstraint is still used when a column has a filter like...

<p:column filterFunction=""...

Right?

@tandraschko
Copy link
Member

not sure but the codepath in FilterMeta ln122 is now dead

@melloware
Copy link
Member Author

Ok let me add some more tests and verify and then I can remove the dead code.

@melloware
Copy link
Member Author

@tandraschko When you say ln122 I think you mean this line:

        FilterConstraint constraint = globalFilterFunction == null
                ? new GlobalFilterConstraint()
                : new FunctionFilterConstraint(globalFilterFunction);

If so I have Integration tests that prove both paths are followed.

GlobalFilterConstraint is used when you have a generic GloblalFilter like in my DataTable001Test.

<p:inputText id="globalFilter" onchange="PF('wgtTable').filter()" placeholder="Enter keyword"/>

FunctionFilterConstraint is used when you have either a custom GloblalFilter or a Column FilterFunction like in my DataTable019Test.

<p:dataTable id="datatable" globalFilterFunction="#{dataTable019.globalFilterFunction}">

<p:column field="type" filterFunction="#{dataTable019.columnFilterFunction}"/>

So I am still not sure there is any dead code and this wasn't the correct change to make. If you have more insight I am happy to write more Integration Tests

@tandraschko
Copy link
Member

The method of ln122 creates the global FilterMeta and reuses globalFilterFunction.
If a globalFilterFunction is defined, you completely skip the global FilterMeta in FilterFeature

@melloware
Copy link
Member Author

I see what you mean now. Removed this code and all Integration Tests are still passing.

melloware added a commit to melloware/primefaces that referenced this issue Feb 7, 2021
@melloware
Copy link
Member Author

@melloware melloware modified the milestones: 10.0.0-RC2, 10.0.0 Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 defect Bug...Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants