Skip to main content
kalyan_chakrav1
Level 2
January 27, 2021
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
Community Advisor
January 29, 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; }
AG

5 replies

BrianKasingli
Adobe Champion and Community Advisor
Adobe Champion and Community Advisor
January 27, 2021

@kalyan_chakrav1,

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

Translate
kalyan_chakrav1
Level 2
January 27, 2021
Using Component exporter i need to get all the child pages based on the homepage path
Translate
arunpatidar
Community Advisor
Community Advisor
January 27, 2021
Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
January 29, 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; }
Translate
AG