Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments

my child tittle is not coming in list in sightly

Avatar

Level 2

Hi 

I written the below sightly and below java code

my requirement is that my level 1 child tittle should come as list but it coming as paragraph, as shown below.

haritha6_0-1659959413457.png

 

***********JAVA CODE**********


import java.util.ArrayList;
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;

//String childTitle;

@inject
@Via("resource")
private String linkLabel;

@inject
@Via("resource")
private String linkPath;

@inject
private String childTitle;

@SlingObject
ResourceResolver resourceResolver;

@Deleted Account
SlingHttpServletRequest request;

@Override
public String getLinkLabel() {
return linkLabel;
}

@Override
public String getLinkPath() {
// TODO Auto-generated method stub
return linkPath;
}

@Override
public ArrayList<String> getChildTitle() {

//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(new PageFilter(false, false), false);
ArrayList<String> childTitles = new ArrayList<String>() ;

while(rootPageIterator.hasNext())
{
childPage = rootPageIterator.next();
childTitle = childPage.getTitle();
childTitles.add(childTitle) ;
logger.info("childTitle inside init === "+childTitle);
//pageList.add(path);

}

return childTitles ;
}


@PostConstruct
protected void init() {

}


}

 

 

 

***************SIGHTLY CODE******

<sly data-sly-use.industryModel="com.aem.sling.model.IndustryModel">

<h2>Haritha test :${industryModel.linkPath}</h2>
<div>

 

<li>

${industryModel.childTitle}

</li>


<div data-sly-list="${industryModel.childTitle}">

</div>


</div>

3 Replies

Avatar

Employee

 

<sly data-sly-use.industryModel="com.aem.sling.model.IndustryModel">
    <h2>Haritha test :${industryModel.linkPath}</h2>
    <ul data-sly-list="${industryModel.childTitle}">
        <li>${item}</li>
    </ul>
</sly>

Your syntax is worng, try above

 

 

Avatar

Level 7

Use below way to print title of all child pages:

 

 

<sly data-sly-use.industryModel="com.aem.sling.model.IndustryModel">
    <h2>${industryModel.linkPath}</h2>
    <ul data-sly-list="${industryModel.childTitle}">
        <li>${item}</li>    //gives title of all child pages as it is the current item in the iteration.
    </ul>
</sly>