Roy Tang

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Notes Photos Links Archives About

Given a JSF/EJB stack, how do I filter the contents of a dataTable listing automatically using the values of a field in a pojo/entity bean?

i.e. I have an entity bean Employee with name field having a value of “John” I would like to use this bean to filter the data table to show only records with name John, and not having to construct the where clause manually?

Comments

I use PrimeFaces' dataTable with filtering and eventually lazy-Loading. Filtering alone is done at a client level, but lazy-loading is done at a server level.

Here you can find some examples.

Both are implemented with Ajax features by PrimeFaces: on typing each character, the filters are applied and the results updated.

With PrimeFaces’ lazy-loading you have also the possibility to handle by yourself the filters: on typing a character in a filter, your implementation of the filter is invoked: with a little of Criteria Builder queries you can write the WHERE conditions in a type-safe and OO way, by building an array of Predicates: this implies that you don’t need to write a single line of sql code.