April 27, 2020
Estimated Post Reading Time ~

How to get the child Pages of a root Page through Java API -AEM/ Adobe CQ5

This post will explain how to get the child Pages of a root Page through Java API in AEM

public static PageFilter getPageFilter() {
 PageFilter pf = new PageFilter(); 
 return pf;
}

public static Iterator<Page> getPageIterator(Page page){
 Iterator<Page> children = page. listChildren(getPageFilter());
 return children;
}

The filter can be changed to restrict child pages e.g Get the child pages created only with the template "/apps/sample/templates/samplePage"

 public static PageFilter getPageFilter() {
 PageFilter pf = new PageFilter() {
 public boolean includes(Page p) {

 ValueMap props = p.getProperties();
 String templatePath = props.get("cq:template",String.class);
 if("/apps/sample/templates/samplePage".equals(templatePath))
 { 
 return true;
 } else
 {
 return false;
 }
 }
 }; 
 return pf;
 }


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.