custom filtering in bean item container

Hi all,

How can we filter first n items in Bean Item container or filter from 1 to 10 (m to n) items. Is it possible to do in Custom Filter.

We can try it by using beanitemcontainer.indexOfId(itemId) in passesFilter method which gives row number. But how to use bean item container object to passesFilter method or even CustomFilter class. Or is it better to use separate column as index for each item in table.

You may be able to do this in a custom filter if the filter has a reference to the container - such a reference is not passed automatically, so you need to give it explicitly to the filter when creating it.

Alternatively, you could override BIC.doFilterContainer() and/or BIC.passesFilters() to make them handle your filters differently, or even do the filtering directly there. This might require calling several protected methods including a deprecated one that may change in a future version, but probably not in a maintenance version.

Note also that such filters can be semantically somewhat ambiguous - should the filtering of the first n items be relative to the unfiltered contents of the container or depend on the results of other filters if there are any?

Hi Henri,

Thanks for your reply. Yes, as you have told, I tried passing the reference of BeanItemContainer to CustomFilter constructor and set the reference to local bean item container variable. But in passesFilter method when i try to use that object and call .indexOfId(itemId) , only -1 is returned.

I am not sure how to pass the reference of container to custom filter and use it. Filtering first n items or from m to n items is with respect to all items in container. It is not dependent on results of any other filter.

Is there any other ways of getting index of itemid in passesFilter method ? Or is there any other way of doing this filtering based on index of items.

indexOfId() is relative to the already filtered set of items, so you probably need to call AbstractInMemoryContainer.getAllItemIds() and check the unfiltered indices there. As the method is protected, you may need to subclass Bean(Item)Container to expose it.