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
January 27, 2021
Solved

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

  • January 27, 2021
  • 3 replies
  • 2827 views

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.
Best answer by Anudeep_Garnepudi

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

3 replies

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

@kalyan_chakrav1,

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

kalyan_chakrav1
Level 2
January 27, 2021
Using Component exporter i need to get all the child pages based on the homepage path
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; }