Returning list of nested child pages at given path in JSON format. after passing the page path | Adobe Higher Education
Skip to main content
kalyan_chakrav1
Level 2
January 27, 2021
Resuelto

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

  • January 27, 2021
  • 5 respuestas
  • 2875 visualizaciones

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

Este tema ha sido cerrado para respuestas.
Mejor respuesta de 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; }

5 respuestas

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

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