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.
-
Create your criterion class by extending
BaseItemSelectorCriterion
. Name the class after the entity it represents and suffix it withItemSelectorCriterion
. 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 forJournal
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; }
-
Create a criterion handler by creating an OSGi component class that implements
BaseItemSelectorCriterionHandler
. This example creates a criterion handler for theTaskItemSelectorCriterion
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; } @Activate @Override protected void activate(BundleContext bundleContext) { super.activate(bundleContext); } }
-
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 withItemSelectorReturnType
. 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{ }