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

Avatar

Avatar

kalyan_chakrav1

Avatar

kalyan_chakrav1

kalyan_chakrav1

27-01-2021

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Anudeep_Garnepudi

MVP

Avatar

Anudeep_Garnepudi

MVP

Anudeep_Garnepudi
MVP

28-01-2021

@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;
}

Answers (2)

Answers (2)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

861

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

861
Arun_Patidar
MVP

27-01-2021

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...

 

Avatar

Avatar

BrianKasingli

MVP

Avatar

BrianKasingli

MVP

BrianKasingli
MVP

27-01-2021

@kalyan_chakrav1,

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