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:

  1. Create a class that is a subclass of atg.service.collections.filter.CachedCollectionFilter

  2. Implement the shouldApplyFilter() method, which is used to determine whether a collection filter should be applied given the execution context. For example, the MembershipFilter would access a user’s membership level and decide if the filter is relevant for that user. Since MembershipFilter supports basic and premier members, which are the only kinds of membership permitted by the site, this method will always return true. If, in the future, the site permits additional membership levels, you would need to revise this method.

  3. 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 of atg.adapter.gsa.ChangeAwareList creates an output type of ArrayList, and an input type of atg.adapter.gsa. ChangeAwareSet creates an output type of HashSet.

  4. 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 by MembershipFilter 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.

  5. Add other methods and properties as necessary. There are no other necessary properties or methods required for the MembershipFilter example.

  6. Create a component for that class, such as /atg/registry/CollectionFilters/MembershipFilter. See the ATG 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).


Copyright © 1997, 2013 Oracle and/or its affiliates. All rights reserved. Legal Notices