jsfprimefaceslazy-loadingprimefaces-datatable

Filtering for value not equal with FilterMeta


I'm trying to migrate a Primefaces Datatable to lazy loading, but I'm finding some problems filtering. With the non-lazy Datatable, filtering just consisted in loading all values from database to some ArrayList, and then filtering them however I wanted with Java stream() or whatever. But with LazyDataModel, filters must be all specified as FilterMeta objects, that are used to build the query to BD so only needed data is loaded from DB.

Sounds fine, and simple filtering is pretty easy to implement with something like this:

FilterMeta fm=FilterMeta.builder()
                .field("status")
                .filterValue(CustomerStatus.NEW)
                .matchMode(MatchMode.EQUALS)
                .build();

Problem comes when I want to implement more complex filters. For example, wanting to filter values different than instead of equal seems an impossible thing. Looking at possible MatchMode values, there's no inequality operator. Only possible values are:

CONTAINS     
ENDS_WITH    
EQUALS   
EXACT    
GLOBAL   
GREATER_THAN     
GREATER_THAN_EQUALS  
IN   
LESS_THAN    
LESS_THAN_EQUALS     
RANGE    
STARTS_WITH

I could do some logic gymnastics, like combining two different filters value>5 and value<5 to mimic value!=5 behaviour, but it looks like very dirty code.

Any idea about what am I missing here? Obvious solution would be FilterMeta implementing some kind of not() or invert() method, but I haven't found anything similar.

Thanks!


Solution

  • After reporting it as a feature request, new negation operators were added in Primefaces 11: https://www.primefaces.org/primefaces-11-0-0-released/