Creating Custom Criterion and Return Types

If an existing criterion or return type doesn’t fit your use case, you can create them. The steps here show you how. For more detailed information on Item Selector criterion and return types, see the Item Selector introduction.

  1. Create your criterion class by extending BaseItemSelectorCriterion. Name the class after the entity it represents and suffix it with ItemSelectorCriterion. You can use the class to pass information to the view if needed. Otherwise, your criterion class can be empty. If you pass information to the view, any fields in your criterion class should be serializable and you should expose an empty public constructor.

    For example, JournalItemSelectorCriterion is the criterion class for Journal entities (Web Content) and passes primary key information to the view:

    public class JournalItemSelectorCriterion extends BaseItemSelectorCriterion {
            public JournalItemSelectorCriterion() {
            public JournalItemSelectorCriterion(long resourcePrimKey) {
                    _resourcePrimKey = resourcePrimKey;
            public long getResourcePrimKey() {
                    return _resourcePrimKey;
            public void setResourcePrimKey(long resourcePrimKey) {
                    _resourcePrimKey = resourcePrimKey;
            private long _resourcePrimKey;
  2. Create a criterion handler by creating an OSGi component class that implements BaseItemSelectorCriterionHandler. This example creates a criterion handler for the TaskItemSelectorCriterion class. The @Activate and @Override tokens are required to activate this OSGi component:

    @Component(service = ItemSelectorCriterionHandler.class)
    public class TaskItemSelectorCriterionHandler extends 
        BaseItemSelectorCriterionHandler<TaskItemSelectorCriterion> {
        public Class <TaskItemSelectorCriterion> getItemSelectorCriterionClass() {
            return TasksItemSelectorCriterionHandler.class;
        protected void activate(BundleContext bundleContext) {
  3. If you need a new return type, create it by implementing ItemSelectorReturnType. Name your return type class after the return type’s data and suffix it with ItemSelectorReturnType. Specify the data and its format in Javadoc. Return type classes need no content. For example, here’s a return type for a task:

    * This return type should return the task ID and the user who
    * created the task as a string.
    * @author Joe Bloggs
    public class TaskItemSelectorReturnType implements ItemSelectorReturnType{

Item Selector

Creating Custom Item Selector Views

Selecting Entities with an Item Selector

« Selecting Entities with an Item SelectorCreating Custom Item Selector Views »
Was this article helpful?
0 out of 0 found this helpful