コミュニティアチーブメントバーを展開する。

Submissions are now open for the 2026 Adobe Experience Maker Awards.
解決済み

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?

トピック

トピックはコミュニティのコンテンツの分類に役立ち、関連コンテンツを発見する可能性を広げます。

1 受け入れられたソリューション

Avatar

正解者
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

元の投稿で解決策を見る

2 返信

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

正解者
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