Get All The Child Nodes/Resources under a Parent Node in AEM | AEM Community Blog Seeding | Community
Skip to main content
kautuk_sahni
Community Manager
Community Manager
February 22, 2022

Get All The Child Nodes/Resources under a Parent Node in AEM | AEM Community Blog Seeding

  • February 22, 2022
  • 0 replies
  • 2879 views

BlogImage.jpg

Get All The Child Nodes/Resources under a Parent Node in AEM by Bimmisoi

Abstract

It is very common scenario where we need to get all the child nodes under a parent node in AEM.

We can use below code :

List childrenList = new ArrayList<>();

public void getAllChildNodes(String parentPath) {
Resource resource = resolver.getResource(parentPath);
collectChildList(resource);
}

private void collectChildList(Resource resource) {
childrenList.add(resource);
if (resource.hasChildren()) {
Iterable ni = resource.getChildren();
for (Resource res : ni) {
collectChildList(res);
}
}
}


ChildrenList will have all the resources under your parent node.

Hope this helps!!

Read Full Blog

Get All The Child Nodes/Resources under a Parent Node in AEM

Q&A

Please use this thread to ask the related questions.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.