AEM - Predicate to list only immediate children

350 views Asked by At

I am using aem-commons's contextualPathBrowser (similar to pathfiled component) in a cq dialog with a predicate property. The java predicate class will evaluate the nodes and only return children pages(cq:Page) in the path picker for user to select from. Predicate class given below:

@Component(
        service = Predicate.class,
        property = {
                "predicate.name=pagePathPredicate"
        }
    )
public class PagePathPredicate extends AbstractNodePredicate {


    @Override
    public boolean evaluate(final Node node) throws AccessDeniedException, ItemNotFoundException, RepositoryException {
        try {
            return isInPredicate(node);
        } catch (RepositoryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }

    private boolean isInPredicate(final Node node) throws RepositoryException {
        if (node.getProperty("jcr:primaryType").getString().equals("cq:Page")) {
            return true;
        }
        return false;
    }
}

The code works well and list only node with jcr:primaryType = cq:Page. However, finding it difficult to list only children pages of the page user is currently on, as I am not sure how to fetch the current resource/node/page in the Predicate class.

0

There are 0 answers