Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

I want to write Recursive method for component nodes which have "container"

Avatar

Level 4

I want a list of components in a page while using recursion method in java

keshava219_2-1703652485790.png

 

parent 1, child 2 , grandchild 3 and there might be another child will also come there 

 

As shown in picture there are some "container" nodes having components inside. For every container node it should get node of the component and add to a java map of values title and heading of the node

NOTE : It should maintain the page order of components

Any reference please?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @keshava219 

 

Please refer to the example on Resource Streams in Apache Sling / Blogs / Perficient

It is exactly what you need "example of how one could extract a stream of resources by a page’s component type under a cq:Page"

 

A suggestion: Do not filter on nodename. Rather use sling:resourceType of container component. If there are sibling containers, except first one all others would have a suffix

 

 


Aanchal Sikka

View solution in original post

2 Replies

Avatar

Level 3

This is good usecase to make use of ResourceStreams. Refer to my article here:

https://medium.com/@bsaravanaprakash/stop-running-aem-queries-on-aemcaas-instead-3add184e7e2a

 

Basically you start from page node, define branch selector and child selector based of your requirement and use foreach to implement the logic. 

 

Hope this helps.

Avatar

Correct answer by
Community Advisor

Hello @keshava219 

 

Please refer to the example on Resource Streams in Apache Sling / Blogs / Perficient

It is exactly what you need "example of how one could extract a stream of resources by a page’s component type under a cq:Page"

 

A suggestion: Do not filter on nodename. Rather use sling:resourceType of container component. If there are sibling containers, except first one all others would have a suffix

 

 


Aanchal Sikka