Keep in mind that when you define a collection filter, you specify a type of object to which it should be applied. Any objects in a collection that have a type other than the specified type will be ignored by the collection filter and included in the result set.
To create a collection filtering component, do the following:
Create a class that is a subclass of
atg.service.collections.filter.CachedCollectionFilter
Implement the
shouldApplyFilter()
method, which is used to determine whether a collection filter should be applied given the execution context. For example, theMembershipFilter
would access a user’s membership level and decide if the filter is relevant for that user. SinceMembershipFilter
supports basic and premier members, which are the only kinds of membership permitted by the site, this method will always returntrue
. If, in the future, the site permits additional membership levels, you would need to revise this method.Implement the
generateFilteredCollection()
method, which is a method used to create an output collection and add the objects that meet the filter condition to it. You need to code this method to specify the data type of the output collection.It is recommended that you use the
generateNewCollectionObject()
method to configure the output collection data type to be the same as the input collection, barring certain restrictions: an input type ofatg.adapter.gsa.ChangeAwareList
creates an output type ofArrayList
, and an input type ofatg.adapter.gsa. ChangeAwareSet
creates an output type ofHashSet
.Implement the
generateContextKey()
method, which is a method used to create a context key object that holds the criteria value for a particular filtering instance. For example, the object created byMembershipFilter
could be an Integer object that represents values 0 (when a user is a basic member) or 1 (when a user is a premier member). For collections that don’t have context specific values, this method should return null.Add other methods and properties as necessary. There are no other necessary properties or methods required for the
MembershipFilter
example.Create a component for that class, such as
/atg/registry/CollectionFilters/MembershipFilter
. See the Platform Programming Guide for instructions on creating components.
The shouldApplyFilter()
, generateFilteredCollection()
, and generateContextKey()
methods, along with several other CachedCollectionFilter
methods, are all overloaded methods with two signatures, one that includes a pExtraParameters
map and another that doesn’t. The pExtraParameters
map allows you to pass additional parameters to a filter so it can do its work. The version of the method that uses pExtraParameters
contains the logic required to perform the given tasks. The method that doesn’t include pExtraParameters
simply calls the method that does and passes in a null map. This use of overloading allows code that calls the original methods to continue to function properly while providing the flexibility to include additional filter parameters when needed. When writing your own implementations, you should implement the version of each method that includes the pExtraPameters
map, so as not to break this logic. For more information, see Passing Additional Parameters to a Filter (Filtering in a Multisite Environment).