Build Or Filter (com.vaadin.data.util.Filter)

Hello,

is it possible to build the Or Filter in a loop?

Eg

Or orFilter = new Or(); for (FilterSet : filter filterSet) { if (filter.isEnabled()) orFilter.add(filter.getFilter()); } Because I got checkboxes, so a user can filter the table, but creating Or-Filters for every possibility is an ugly and long task.

Thanks for your help.

Hey Thomas,

Perhaps you can create the filters you need (one per checkbox?), and just instantiate a new Or filter when the filtering changes (using the Or(Filters… filters) constructor)?

Hello,

I can do that and set one filter (when the value from the CheckBox changes to false) to null, but then I can’t create the Or Filter (Nullpointer).

So I need the possibility to add or remove filters from the Or Filter.

(Like a Criteria in JPA)

Hey,

You could reset the Or filter (via instantiation) each time, unless you want to go the custom route of course. If you check the implementation you’ll see that the member field filters is an unmodifiable list. You can of course call getFilters, make a copy, add/remove filters as you please, and then reset/create a new Or filter.

Thank you for your help, it worked but it’s quite an odd task …

 containerSubsequent.removeContainerFilter(or);
 Collection<Container.Filter> f1 = new ArrayList<Container.Filter>(or.getFilters());
 f1.add(filter1); // .remove(filter1);
 or = new Or(f1.toArray(new Container.Filter[0]
));

 containerSubsequent.addContainerFilter(or);