내 커뮤니티 업적 표시줄을 확대합니다.

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

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Returning list of nested child pages at given path in JSON format. after passing the page path

Avatar

Level 2

Code sample to get the list of nested child pages at a given path in json format using componentexporter

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Community Advisor

@kalyan_chakrav1 

Check the below code snippet, hope this is what you are expecting.

@SlingObject
ResourceResolver resourceResolver;

@Self
SlingHttpServletRequest request;

private List<String> children = new ArrayList<String>();


private String root = "/content/test";

@PostConstruct
protected void initialize() {
    Page rootPage = resourceResolver.getResource(root).adaptTo(Page.class);
    Iterator<Page> listChildren = rootPage.listChildren(null, true);
    while(listChildren.hasNext()) {
	children.add(listChildren.next().getPath());
    }
}

public List<String> getChildren() {
	return children;
}

public String getRoot() {
	return root;
}

원본 게시물의 솔루션 보기

5 답변 개

Avatar

Community Advisor and Adobe Champion

@kalyan_chakrav1,

Can you please elaborate on your question? It is not making sense...

Avatar

Level 2
Using Component exporter i need to get all the child pages based on the homepage path

Avatar

Community Advisor and Adobe Champion

The component exporter's purpose is to output JSON from your sling model's properties via Apache Sling provides a Jackson JSON exporter. What you can do is write a recursive method that will traverse through each and every node, from the root node, and save each parent within a List<Page> object. Once your List<Page> is generated, you can simply create a getter for List<Page>, and calling model.json, you will get a JSON representation of all the child pages, recursively.

Take a look at ACS Common's sitemap generator, as they recusively traverse through every node to construct the sitemap.xml, https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/ad...

 

 

Avatar

Community Advisor

Please use Page APi in your model to get all the page and create json based on results 

https://helpx.adobe.com/experience-manager/6-2/sites/developing/using/reference-materials/javadoc/co...

 

Arun Patidar

AEM LinksLinkedIn

Avatar

정확한 답변 작성자:
Community Advisor

@kalyan_chakrav1 

Check the below code snippet, hope this is what you are expecting.

@SlingObject
ResourceResolver resourceResolver;

@Self
SlingHttpServletRequest request;

private List<String> children = new ArrayList<String>();


private String root = "/content/test";

@PostConstruct
protected void initialize() {
    Page rootPage = resourceResolver.getResource(root).adaptTo(Page.class);
    Iterator<Page> listChildren = rootPage.listChildren(null, true);
    while(listChildren.hasNext()) {
	children.add(listChildren.next().getPath());
    }
}

public List<String> getChildren() {
	return children;
}

public String getRoot() {
	return root;
}