Datatable - Using FilterFeature changes value type

UI Components for JSF
Post Reply
danio73
Posts: 4
Joined: 01 Feb 2018, 16:21

02 Jun 2023, 17:07

Hi all,

We have a strange behavior with the datatable & filters, we are using internaly a custom ListModel with some additional data.
If we load our datatable and select lines, sort columns, no issues at all.
But when we first do a filter on one column, the value type of the datatable is modified and is never restored.

As far as i can see it seems related to the FilterFeature that calls setValue with an ArrayList type instead of the original model.

End of FilterFeature.filter():

Code: Select all

        //save filtered data
        table.setFilteredValue(filtered);
        table.setValue(filtered);
        table.setRowIndex(-1); //reset datamodel
        
I reproduce the case easily with a simple test, using a basic datatable with one colum with sort and filter, and a simple dataModel.

DataModel:

Code: Select all

public class TableModel<E>
    extends
    ListDataModel<E>
    implements
    Serializable
{
    public TableModel(List<E> datasource)
    {
        super(datasource);
    }
}
Page: (Binding is just used here to display easily the value type inside the component)

Code: Select all

 <p:dataTable id="cars" var="car"
       value="#{tableController.dataModelSingle}"
       rowKey="#{car.model}" sortBy="#{car.manufacturer}"
       binding="#{tableController.table}"
       widgetVar="carsEdition">
            ...
 </dataTable >
So with sorting or even selecting lines, no changes on the value type.
But when filter is used the first time we can see using the binding attribute that the value type as changed.

Logs showing the value type, on page first load, then on sort, and finaly after a filter:

Code: Select all

16:37:10,379 ERROR [stderr]  class com.test.TableModel
16:37:13,940 ERROR [stderr]  class com.test.TableModel
16:37:19,922 ERROR [stderr]  class java.util.ArrayList
Also note, that we were using Primefaces 6.1 previously and the value type was still ok after filtering.

Wish the use case is clear,

Thanks
Primefaces 12.0.4
JBoss EAP 7.4.5

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

05 Jun 2023, 15:31

If you upgrade PF 6 to PF 12 you will see a ton has has changed about the Datatable and things have been corrected and refactored correctly. So most likely your old code was working around a problem that has since been fixed.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

danio73
Posts: 4
Joined: 01 Feb 2018, 16:21

05 Jun 2023, 17:46

Hi,

yes of course i know, that's why my test is just using Primefaces component directly.
In the case i show there is no specific code juste the datatable with a controller and a binding to display the instanceof of the value component.

And the goal was to know if it was normal after calling the FilterFeature that the object type of the value is changed to a list and never recovered.
Does it means when using filter we must avoid the use of any Model like ListDataModel and use ONLY List<> objects ? Or is it not normal that the object type is changed to a simple List ?

Thanks
Primefaces 12.0.4
JBoss EAP 7.4.5

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

05 Jun 2023, 18:57

I don't think so can you put together a small PrimeFaces Test reproducer of what you are trying to do?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

danio73
Posts: 4
Joined: 01 Feb 2018, 16:21

06 Jun 2023, 14:22

Hi,

yes sure. i made a simple project using your primefaces test project.

You will find the project here:
https://github.com/rsi21/primefaces-tes ... ith_filter

There is a datatable with some data displayed and i show on top the type of the table value.

At arrival or without any action you will see value type is a TestModel. If we use sorting, same thing it remains a TestModel.
When starting using filter on first column it becomes an ArrayList and remains like this (if sorting again for example).
If you remove the filtering value then it becomes again a TestModel.

Hope it helps
Primefaces 12.0.4
JBoss EAP 7.4.5

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

06 Jun 2023, 20:51

@danio73 ok can you open a GitHub Issue with your reproducer attached please.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

danio73
Posts: 4
Joined: 01 Feb 2018, 16:21

05 Jul 2023, 10:21

Hi,

For information, the issue was opened here:
https://github.com/primefaces/primefaces/issues/10209
And it was fixed in primefaces 13.0.0-RC2

Thanks for the quick fix!
Primefaces 12.0.4
JBoss EAP 7.4.5

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests