Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
GELÖST

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?

Themen

Anhand von Themen werden Community-Inhalte kategorisiert und Sie können so relevanten Inhalt besser finden.

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
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

Lösung in ursprünglichem Beitrag anzeigen

2 Antworten

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

Korrekte Antwort von
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