Returning list of nested child pages at given path in JSON format. after passing the page path | Community
Skip to main content
kalyan_chakrav1
Level 2
Jan 27, 2021 1:36 PM UTC
Solved

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

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Anudeep_Garnepudi
Anudeep_GarnepudiAccepted solution
New Participant
Jan 29, 2021 7:23 AM UTC

@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 replies

Anudeep_Garnepudi
Anudeep_GarnepudiAccepted solution
New Participant
Jan 29, 2021 7:23 AM UTC

@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; }
Translate
arunpatidar
New Participant
Jan 27, 2021 4:31 PM UTC
BrianKasingli
New Participant
Jan 27, 2021 1:49 PM UTC

@kalyan_chakrav1,

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

Translate
kalyan_chakrav1
Level 2
Jan 27, 2021 3:55 PM UTC
Using Component exporter i need to get all the child pages based on the homepage path
Translate