Retrieve all the components has specific resource type in the given page without query builder | Community
Skip to main content
Level 3
Jul 21, 2023 7:16 AM UTC
Solved

Retrieve all the components has specific resource type in the given page without query builder

Hello All ,

 

I need to retrieve the component values that match with specific resource type and read the component values. We can have n number of the same components on the given page.

 

Please provide any suggestions

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Manu_Mathew_
Manu_Mathew_Accepted solution
New Participant
Jul 22, 2023 10:00 AM UTC

@sateeshkreddy You could use sling APIs to do so-

Take a root path

loop the resource and nodes as per your requirement via listchildren, Iterators,hasNode() etc until the leaf node.

use value map object - eg: currentResource.getValueMap()

compare the slingResourceType and read your values.

 

You could use the querybuilder to get the list of resources using a resource type rather than looping, Is there any particular reason you don't want to use the query builder? You could also index it if needed.

 

2 replies

Manu_Mathew_
Manu_Mathew_Accepted solution
New Participant
Jul 22, 2023 10:00 AM UTC

@sateeshkreddy You could use sling APIs to do so-

Take a root path

loop the resource and nodes as per your requirement via listchildren, Iterators,hasNode() etc until the leaf node.

use value map object - eg: currentResource.getValueMap()

compare the slingResourceType and read your values.

 

You could use the querybuilder to get the list of resources using a resource type rather than looping, Is there any particular reason you don't want to use the query builder? You could also index it if needed.

 

Translate
ayushmishra07
Employee
Jul 21, 2023 8:45 AM UTC

Hi @sateeshkreddy ,

Can you please confirm if you want the list of matching components from one page only or list of all the matching components from the current as well as child page.

Translate