1

I have a requirement where the AEM pathfield component will show only the child(cq:Page ) resources/nodes of the current node(cq:Page) in the options picker. I went through the documentation https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/pathfield/index.html , not sure the filter option can be of use.

@Component(
        service = Predicate.class,
        property = {
                "predicate.name= myPredicateName"
        }
    )
public class MyPredicate extends AbstractNodePredicate {
    private static final LocalisedLogger LOG = LocalisedLoggerFactory.getLogger(MyPredicate.class);

    @Override
    public boolean evaluate(final Node node) {
        LOG.log(Messages.DEBUG, "testing" + node.toString());
        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.hasProperty("jcr:content/dog")) {
            return true;
        }
        return false;
    }
}

content.xml

<path
                                                        jcr:primaryType="nt:unstructured"
                                                        sling:resourceType="granite/ui/components/coral/foundation/form/pathfield"
                                                        fieldLabel="Page Path"
                                                        predicate="[myPredicateName]"
                                                        emptyText="Select the carousels page"
                                                        name="./carouselsPagePath"
                                                        forceSelection="{Boolean}true"
                                                        required="{Boolean}true"/>
infinityskyline
  • 369
  • 2
  • 4
  • 17
  • 1
    It should be possible to implement your own predicate by extending `com.day.cq.commons.predicate.AbstractNodePredicate`. I haven't used it since at least AEM 6.3 but it should still work. Have a look at the snippets I posted in this question https://stackoverflow.com/questions/41677562/how-to-filter-the-pages-visible-in-an-aem-granite-ui-path-browser Unfortunately, choosing just the children on the node the component is placed on could be tricky. The way I understand this interface is that it acts as a visitor and operates on each individual `Node` as the content tree is traversed. – toniedzwiedz Nov 24 '20 at 16:21
  • That makes sense. Any idea how to use this predicate in the pathfield component because adding predicate="myPredicateName" in the cq dialogue xml doesn't seem to work. – infinityskyline Nov 25 '20 at 10:34
  • It's been a while but I think the property expects a list. Try `predicate="[myPredicateName]"` – toniedzwiedz Nov 25 '20 at 10:39
  • no luck. I have added the code to the question. – infinityskyline Nov 26 '20 at 11:18

0 Answers0