Extending the Filter Component

In this guide I will show, generally, how to alter the behavior of the filter condition selection screen and, specifically, allow for the explicit inclusion of properties in the filter in a way similar to the excludeProperties attribute of the Filter.

Motivation: I found the include attribute to be lacking for 4 reasons.

  1. Let’s be honest, regex is tedious.
  2. The include attribute only applies to the top level attributes of the Filter’s MetaClass. There is no control over the lower levels of the hierarchy.
  3. Sometimes it is easier to explicitly include attributes than to exhaustively exclude the unwanted ones.
  4. Many times I did not want to show the child attributes of an entity association.

I will extend the Pet Clinic example found here.

Steps:

  1. Extend the ConditionDescriptorsTreeBuilder class. The new extended class must be included in the web module of the project. Here is my implementation. ExtConditionDescriptorsTreeBuilder.java (13.3 KB)

  2. Add a new bean entry to web-spring.xml like so: web-spring.xml (896 Bytes)

Usage:

  • Add a new attribute includeProperties to the properties element of the Filter descriptor with a list of property paths relative to the metaClass of the filter. Only explicit property paths are included in the filter.

Example: includeProperties="pet.owner" on the VisitBrowse screen will generate the following filter selection screen:

  • Additionally, '+' can be used to include all non-system attributes at a given level in the hierarchy. Similarly, '*' can be used to include all attributes.

Example: includeProperties="+" on the VisitBrowse screen will generate the following filter selection screen:

  • '+' and '*' can be appended to properties in paths to concisely include all attributes along a given path.

Example: includeProperties="pet+.owner+" on the VisitBrowse screen will generate the following filter selection screen:

  • includeProperties works in conjunction with excludeProperties.

Let me know if you have an questions, comments, or further extensions.

4 Likes

Great idea and implementation!

Created an issue for Jmix: https://github.com/Haulmont/jmix-ui/issues/771
If you switch to Jmix at some point, feel free to submit a PR for this feature :wink:

1 Like