Skip to main content
Level 4
October 4, 2016

unable to get the List of objects using Java Use API and Sightly(Htl)

I am trying to get a List of custom object of type linked list into html using Sightly. But I a unable to read them in sightly. Sample Code is pasted below:

Java Bean:

public class MiniNavBean {

private String fPath;
    
private String activeAttr;

public MiniNavBean(String fPath, String activeAttr){
        
        this.fPath = fPath;
        this.activeAttr = activeAttr;
    }

public String getFpath() {
        return fPath;
    }

    public void setFpath(String fpath) {
        this.fPath = fpath;
    }

    public String getActiveattr() {
        return activeAttr;
    }

    public void setActiveattr(String activeattr) {
        this.activeAttr = activeattr;
    }

}

Java class which extends WCMUsePojo:

public class MiniNav extends WCMUsePojo {

private List<MiniNavBean> navList;
   
MiniNavBean miniNav;
    
    public List<MiniNavBean> getNavList() {
        return navList;
    }


    public void setNavList(List<MiniNavBean> navList) {
        this.navList = navList;
    }

@Override
    public void activate() {

navList = new LinkedList<MiniNavBean>();

fPath = "fpaths";

activeAttr = "activeattrs;"       

miniNav = new MiniNavBean(fpath, activeattr);

navList.add(miniNav);

}

}

Html file (Sightly):

<div data-sly-include="/apps/project/components/global.jsp"></div>
<div data-sly-use.mininav="com.components.MiniNav" data-sly-unwrap>

<div data-sly-list.navlist="${mininav.navList}">
                <li>
                <p>${navlist.fPath}</p>
                <p>${navlist.activeAttr}</p>
                </li>

</div>

 

When I am trying to execute the above code, I am able to see the linked list getting instantiated with the data in the java class. However when I am trying to display the values of the list in the front end, sightly is unable to read it.

Since the LinkedList is of CustomObject type(MiniNavBean) I suspect sightly is unable to read it as it doesn't know about this bean because we didn't refer that bean anywhere. Is there a way to fix this using sightly tags and read the data ?

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

16 replies

Feike_Visser1
Adobe Employee
Adobe Employee
October 4, 2016

In your sample I don't see any assignments to the List<> variable..

private List<MiniNavBean> navList;

Translate
Feike_Visser1
Adobe Employee
Adobe Employee
October 4, 2016

On the sightly syntax, you can also use the following:

<div data-sly-use.mininav="com.components.MiniNav" data-sly-list.navlist="${mininav.navList}">

No need for the global.jsp, and you can combine data-sly attributes within an element

Translate
nalla0109Author
Level 4
October 4, 2016

Does it matter if I combine data-sly-attributes within an element or not. I need to display the values of the mainnav bean object which is part of linked list. 

Translate
smacdonald2008
Level 10
October 4, 2016

See this article that shows you the syntax - also be sure to use WCMUsePojo:

https://helpx.adobe.com/experience-manager/using/htl_61.html

Hope this helps... 

Translate