Show the level1 child pages in my sightly
Hi All,
I am using AEM 6.5 and using the below code for showing only level1 child page from the path /content/testing/en/india.
But the issue is the it is showing all the child pages means level 1 , level 2 and level 3 etc. under /content/testing/en/india.
Below are my code.
********************************** JAVA ******************************************
import java.util.Iterator;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageFilter;
import com.day.cq.wcm.api.PageManager;
import com.te.aem.sling.model.IndustryModel;
@Model(adaptables = SlingHttpServletRequest.class,
adapters = IndustryModel.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class IndustryModelImpl implements IndustryModel {
private static final Logger logger = LoggerFactory.getLogger(IndustryModelImpl.class);
Page childPage;
@586265
@2434638("resource")
private String linkLabel;
@586265
@2434638("resource")
private String linkPath;
@SlingObject
ResourceResolver resourceResolver;
@1961677
SlingHttpServletRequest request;
@9944223
public String getLinkLabel() {
return linkLabel;
}
@9944223
public String getLinkPath() {
//childTitle=linkPath;
return linkPath;
}
@PostConstruct
protected void init() {
logger.info("linkLabel ====== " + linkLabel);
logger.info("linkPath ============ " + linkPath);
//String children = linkPath;
ResourceResolver resourceResolver = request.getResourceResolver();
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
//ArrayList pageList = new ArrayList();
Page rootPage = pageManager.getPage(linkPath);
logger.info("rootPage === ++++++++++++ " + rootPage);
//Page rootPage = linkPath;
Iterator<Page> rootPageIterator = rootPage.listChildren(null, false);
//Iterator<Page> rootPageIterator = rootPage.listChildren(new PageFilter(), true);
//Iterator<Page> rootPageIterator = rootPage.listChildren();
while(rootPageIterator.hasNext())
{
childPage = rootPageIterator.next();
String childTitle = childPage.getTitle();
logger.info("childTitle === "+childTitle);
//pageList.add(path);
}
}
}
*************************************** SIGHTLY **************************************
<sly data-sly-use.industryModel="com.test.aem.sling.model.IndustryModel">
<h2>Haritha test :${industryModel.linkPath}</h2>