I need to place my all child nodes in navigation according to parent node
Need to (navtitle and navlinks) and also the (Subnavtitle and Subnavlinks)
package com.kohler.jacobdelafon.core.models;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.kohler.jacobdelafon.core.beans.NavigationLinks;
@Model(adaptables = Resource.class)
public class JDHeaderNavigation {
private static final Logger LOG = LoggerFactory.getLogger(JDHeaderNavigation.class);
@Inject
@Optional
private String rootPath;
@Inject
private ResourceResolver resolver;
private List<NavigationLinks> navigationLinksList;
private List<NavigationLinks> subNavLinksList;
private LinkedHashMap<NavigationLinks, List<NavigationLinks>> pagesListMap = new LinkedHashMap<>();
public LinkedHashMap<NavigationLinks, List<NavigationLinks>> getNavigationLinksList() {
return pagesListMap;
}
public String subnavtitle;
public void display() {
LOG.info("Inside Display");
Iterator sample = pagesListMap.keySet().iterator();
while (sample.hasNext()) {
String str = sample.next().toString();
LOG.info("String+ " + str);
}
}
@PostConstruct
public void init() {
LOG.debug("inside getNavigationLinksList");
try {
if (resolver != null && rootPath != null) {
Page rootPage = resolver.adaptTo(PageManager.class).getPage(rootPath);
LOG.info("rootpage+rootpage===========" + rootPage.getPath());
navigationLinksList = new ArrayList<NavigationLinks>();
subNavLinksList = new ArrayList<>();
if (rootPage != null) {
Iterator<Page> children = rootPage.listChildren();
while (children.hasNext()) {
NavigationLinks navigation = new NavigationLinks();
Page child = children.next();
if (!child.isHideInNav()) {
String firstLevelTitle = (null != child.getTitle()) ? child.getTitle() : "";
navigation.setNavTitle(firstLevelTitle);
navigation.setNavLink(child.getPath());
navigationLinksList.add(navigation);
Iterator<Page> grandChildren = child.listChildren();
subNavLinksList = new ArrayList<>();
while (grandChildren.hasNext()) {
NavigationLinks navigation1 = new NavigationLinks();
Page grand = grandChildren.next();
if (!grand.isHideInNav()) {
navigation1.setNavTitle((null != grand.getTitle()) ? grand.getTitle() : "");
navigation1.setNavLink(grand.getPath());
subNavLinksList.add(navigation1);
}
}
pagesListMap.put(navigation, subNavLinksList);
}
}
}
}
} catch (Exception ex) {
LOG.debug("inside exception " + ex.toString());
LOG.error(ex.toString());
}
for (Entry<NavigationLinks, List<NavigationLinks>> en : pagesListMap.entrySet()) {
NavigationLinks obj1 = en.getKey();
LOG.info("Parent: " + obj1.getNavTitle() + "," + obj1.getNavLink());
for (NavigationLinks obj : en.getValue()) {
LOG.info("Children: " + obj.getNavTitle() + "," + obj.getNavLink());
subnavtitle=obj.getNavTitle();
}
}
display();
}
}
--------------------------------------------------------------------------

<------------------------component Html----------------------->
<sly data-sly-use.nav="com.kohler.jacobdelafon.core.models.JDHeaderNavigation" />
<sly data-sly-list="${nav.navigationLinksList}">
<a href="${item.navLink}.html">${item.navTitle}</a>
${subnavtitle}
</sly>
----------------------------------------------------------------------
giving me only the parent node with links and logs showing me with child names please help me
