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

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

Mark Solution

この会話は、活動がないためロックされています。新しい投稿を作成してください。

解決済み

List of components

Avatar

Level 2

How to fetch list of components configured on current page?

I tried 

ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
Collection<com.day.cq.wcm.api.components.Component> components = componentManager.getComponents();

for (com.day.cq.wcm.api.components.Component component : components) {
if (component.getPath().startsWith("/apps")) {
}
}

but it 's not listing the exact components which has been configured on the page.
Any other way can someone answer may be with predicate query or something easier and efficient way?

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

Avatar

正解者
Community Advisor

you can write same logic in service as well.

Groovy is a java scripting language. 

1. Get the current page/jcr:content node

2. get all the children node (recursive) and collect the resources in a Set

 

code example https://aemlab.blogspot.com/2019/07/get-json-response-of-aem-page.html  

Arun Patidar

AEM LinksLinkedIn

元の投稿で解決策を見る

4 返信

Avatar

Community Advisor

You can get current page's jcr:content node and get all its children using getNodes() and check the sling:resourceType property of the components whose value starts like example "companyName" if you have components under /apps/companyName. 

 

Some groovy script example discussed here

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/solved-find-all-the-compon... 

 

 

 

Avatar

Level 2

@Saravanan_Dharmaraj I don't want to have it in groovy script -  I want to implement in service.

Avatar

正解者
Community Advisor

you can write same logic in service as well.

Groovy is a java scripting language. 

1. Get the current page/jcr:content node

2. get all the children node (recursive) and collect the resources in a Set

 

code example https://aemlab.blogspot.com/2019/07/get-json-response-of-aem-page.html  

Arun Patidar

AEM LinksLinkedIn

Avatar

Community Advisor

Also, the other approach, you can get page json directly with below url: 

http://localhost:4502/{pagepath}.{level}.json

Here level is the location where all the components presents. 

Eg:  http://localhost:4502/content/wknd/us/en/magazine/guide-la-skateparks.5.json once you have the json, you can parse the way you want.