Vaadin is available in version 6.6 preview since this week. Among other interesting enhancements, one surely caught my attention, the new Filter API.
To understand why it’s so interesting, one must know how it’s handled in version 6.5 and before.
But first, a word about filters in Vaadin: they are used in containers, which handle collections of items, in order to sort out eligible items.
The Container.Filterable
interface define a method to add a single filter, whose signature is:
addContainerFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix)
So, we can only filter on string equality, and this equality can be loosened/tightened toward case and position. Morevoer, filters on the same property are additive. If you need to go beyond that, your goose is cooked. In a previous proposal to a request, the filter had to be accent insensitive, which is not supported. I had to hack like mad to implement it. In effect, since most of the container API’s code is private, I copied it to offer the needed option alternative. It did the trick but it’s pretty dirty.
However, the new API supplies a true extensible model for filters which renders my previous development obsolete. Facts worth mentioning are the following:
- The
Container.Filterable
interface becomesContainer.SimpleFilterable
, with no other changes in the method signatures - A brand-new
Container.Filterable
is added, with the method:
addContainerFilter(Container.Filter filter)
- The Filter interface becomes public, and brings an entire hierarchy, with boolean composition in mind (meaning you can OR, AND or NOT you filters in combination). The interface has two methods:
appliesToProperty(Object propertyId)
passesFilter(Object itemId, Item item)
These updates make creating an accent-insensitive a breeze. Conclusion is, if you’re interested in Vaadin, you have to take a look at the new version, if only for the filter API!