- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
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<Resource> 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<Resource> ni = resource.getChildren(); for (Resource res : ni) { collectChildList(res); } } }
ChildrenList will have all the resources under your parent node.
Hope this helps!!
Happy Coding 🙏
Adobe Experience Manager
AEM
AEM 6.5
AEM as a Cloud Service
AEM SDK
AEMaaCS
Child Nodes
Get All The Child Nodes under a Parent Node
iterator
Node iterator
Parent Node
Resource iterator
Resources
- Get link
- X
- Other Apps
Comments
Thanks for sharing !!
ReplyDeleteHappy to Help
Delete