Home » Java » java – The method addFilter(SerializablePredicate) in the type InMemoryDataProvider is not applicable for the arguments (( desc) -> {})-Exceptionshub

java – The method addFilter(SerializablePredicate) in the type InMemoryDataProvider is not applicable for the arguments (( desc) -> {})-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am playing around with Vaadin and now I am trying to add a filter to a Grid that gets it data via JPA and a MySQL DB. It should be very simple and I am rigorously following the examples shown here. All seems to be going well until I get this eponymous error message.

This is how I have set up the class data communication.

    @Autowired
    CoreRepository crp;     
    @Id("descriptionFilter")
    private TextField descriptionFilter;
    List<db> list = crp.findAll();
    ListDataProvider<db> ldp = DataProvider.ofCollection(list);
    grid.setDataProvider(ldp);

And the filtering:

    /* Filtration */
    descriptionFilter.addValueChangeListener( e->
    {
        Notification.show(e.getValue());

        ldp.addFilter(desc -> 
        {
            StringUtils.containsIgnoreCase(desc.getFileDescription(), descriptionFilter.getValue()); //<< I get the error here
        });
    });     
    descriptionFilter.setValueChangeMode(ValueChangeMode.EAGER);

However, I get this error and I do not understand how this is happening

The method addFilter(SerializablePredicate) in the
type InMemoryDataProvider is not applicable for the
arguments (( desc) -> {})

What could I be possibly doing wrong?

How to&Answers:

It has to be a SerializablePredicate, so it must return a boolean:

ldp.addFilter(desc -> 
{
    return StringUtils.containsIgnoreCase(desc.getFileDescription(), descriptionFilter.getValue());
})

or even simpler:

ldp.addFilter(desc -> StringUtils.containsIgnoreCase(desc.getFileDescription(), descriptionFilter.getValue()));