AEM - Predicate to list only immediate children | Community
Skip to main content
Level 2
December 1, 2020
Solved

AEM - Predicate to list only immediate children

  • December 1, 2020
  • 1 reply
  • 2305 views

I am using aem-commons's contextualPathBrowser (similar to pathfiled component) 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 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.  Or is there a better way to solve this? I don't know how to use query builder.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by shelly-goel

@infinityskyline  I would suggest to go with a clientlib (categories cq.authoring.dialog) where you would be able to get the current page and add your filter logic as needed. An example below:

http://experience-aem.blogspot.com/2016/04/aem-62-touch-ui-path-browser-filter-for-autocomplete-and-picker-results.html

Here current page path is set as the default value though you can tweak it as per your requirements and set the rootPath based on current page path alongwith the filtering logic.

1 reply

shelly-goel
Adobe Employee
shelly-goelAdobe EmployeeAccepted solution
Adobe Employee
December 2, 2020

@infinityskyline  I would suggest to go with a clientlib (categories cq.authoring.dialog) where you would be able to get the current page and add your filter logic as needed. An example below:

http://experience-aem.blogspot.com/2016/04/aem-62-touch-ui-path-browser-filter-for-autocomplete-and-picker-results.html

Here current page path is set as the default value though you can tweak it as per your requirements and set the rootPath based on current page path alongwith the filtering logic.

Level 2
December 2, 2020
@716105 I am getting "'Granite' is not defined"