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.
- Let’s be honest, regex is tedious.
- 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. - Sometimes it is easier to explicitly include attributes than to exhaustively exclude the unwanted ones.
- 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:
-
Extend the
ConditionDescriptorsTreeBuilder
class. The new extended class must be included in theweb
module of the project. Here is my implementation. ExtConditionDescriptorsTreeBuilder.java (13.3 KB) -
Add a new bean entry to
web-spring.xml
like so: web-spring.xml (896 Bytes)
Usage:
- Add a new attribute
includeProperties
to theproperties
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 withexcludeProperties
.
Let me know if you have an questions, comments, or further extensions.