활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
Code sample to get the list of nested child pages at a given path in json format using componentexporter
해결되었습니다! 솔루션으로 이동.
조회 수
답글
좋아요 수
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;
}
Can you please elaborate on your question? It is not making sense...
조회 수
답글
좋아요 수
The component exporter's purpose is to output JSON from your sling model's properties via Apache Sling provides a Jackson JSON exporter. What you can do is write a recursive method that will traverse through each and every node, from the root node, and save each parent within a List<Page> object. Once your List<Page> is generated, you can simply create a getter for List<Page>, and calling model.json, you will get a JSON representation of all the child pages, recursively.
Take a look at ACS Common's sitemap generator, as they recusively traverse through every node to construct the sitemap.xml, https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/ad...
조회 수
답글
좋아요 수
Please use Page APi in your model to get all the page and create json based on results
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;
}