Home > JavaEE > New Filter API in Vaadin 6.6

New Filter API in Vaadin 6.6

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 becomes Container.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!

To go further:

  • Vaadin 6.6.0 pre1 is available here
email
Categories: JavaEE Tags:
  1. May 2nd, 2011 at 10:00 | #1

    Thanks for this info. Exactly what i was looking for.

    Actually we are working on redvaadin. A framework which offers base infrastructure functionality for any kind of applications. We are going to contribute this framework as an vaadin addon in a few weeks when we are finished.
    The componentents of this framework are based on container and i need to filter the items on a very general way.
    Thanks, Florian

  2. miku
    May 12th, 2011 at 12:12 | #2

    I don’t know how or why I stumbled upon your blog post, but this is something I’ve been waiting for a while. I already implemented the “custom filter” hack and was hoping for a native implementation :) Thanks. I probably wouldn’t have noticed the new feature without this post.

  1. No trackbacks yet.