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 abstract 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 our site, this method will always return true. If, in the future, your site permits additional membership levels, you would need to revise this method.

  3. Implement the generateFilteredCollection method, which is an abstract 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 an abstract 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 Programming Guide for instructions on creating components.

loading table of contents...