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

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

rohitn62196663
Level 4
Level 4

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 ?

16 Replies