I want to write Recursive method for component nodes which have "container" | Community
Skip to main content
keshava219
New Participant
December 27, 2023
Solved

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

  • December 27, 2023
  • 2 replies
  • 857 views

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

 

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by aanchal-sikka

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

 

 

2 replies

aanchal-sikka
aanchal-sikkaAccepted solution
New Participant
December 27, 2023

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
New Participant
December 27, 2023

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.