I need to place my all child nodes in navigation according to parent node | Community
Skip to main content
Level 3
June 11, 2019

I need to place my all child nodes in navigation according to parent node

  • June 11, 2019
  • 2 replies
  • 4572 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Brandon_Loshe
June 11, 2019

Hi keshav goud,

I'm seeing that this is posted to the Encore forums. To get you better assistance, what app forum should this actually be moved to?

Level 3
June 12, 2019

Hi Brandon Loshe ,

thanks for your reply,

Kindly guide me about what is what app forum can me send me any reference.

June 12, 2019

What Adobe program are you using?

June 12, 2019

Did you write that Java code or copy it from somewhere?

The reason I am asking is that it seems strange that you know how to write that Java code for Experience Manager yet post in a Encore forum. 

Level 3
June 13, 2019

Hi,

joeb216688728,

i know how to write java code but how present in the page that i need to know and  i think some changes in the java code also.

thanks for your reply