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
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Validate 10
Level 3
rohitn62196663
Level 3

Likes

12 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 3
rohitn62196663
Level 3

Likes

12 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
rohitn62196663
Level 3

04-10-2016

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 ?

Replies

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

04-10-2016

Here my sample:

package adobe.summit.lasvegas.core;

 

import java.util.LinkedList;

import java.util.List;

 

import com.adobe.cq.sightly.WCMUsePojo;

 

public class MiniNav extends WCMUsePojo {

 

    private List<MiniNavBean> navList = new LinkedList<MiniNavBean>();

 

    MiniNavBean miniNav;

 

    public List<MiniNavBean> getNavList() {

        return navList;

    }

 

    public void setNavList(List<MiniNavBean> navList) {

        this.navList = navList;

    }

 

@Override

    public void activate() {

 

        miniNav = new MiniNavBean("fpaths", "activeattrs");

 

        navList.add(miniNav);

 

    }

 

}

 

HTL:

<div data-sly-use.mininav="adobe.summit.lasvegas.core.MiniNav" data-sly-list.navlist="${mininav.navList}">
                <li>
                <p>${navlist.activeattr}</p>
                </li>

</div>

Avatar

Avatar
Validate 10
Level 3
rohitn62196663
Level 3

Likes

12 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 3
rohitn62196663
Level 3

Likes

12 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
rohitn62196663
Level 3

04-10-2016

My code is similar to yours, but wondering why is it not working on my end:
 

Code sample:

 

public class MiniNav extends WCMUsePojo {


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


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


    @Override
    public void activate() {
        
        navList = new LinkedList<MiniNavBean>();
        MiniNavBean miniNavObj = new MiniNavBean("fpath", "activeattr", "scptitle");
        navList.add(miniNavObj);
        
    }

}

 

Sighly:

<div data-sly-include="/apps/<application>/components/global.jsp"></div>
<div data-sly-use.mininav="com.xxx.totalinsight.components.MiniNav" data-sly-list.navlist="${mininav.navList}" data-sly-unwrap>
    <div class="content center">
        <div class="itemsList">
            <ul>
                <li>
                    <p>fpath : ${navlist.fPath}</p>
                    <p>activeAttr: ${navlist.activeAttr}</p>
                </li>
            </ul>
        </div>
    </div>
</div>

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

04-10-2016

Can you share your bean too?

Avatar

Avatar
Validate 10
Level 3
rohitn62196663
Level 3

Likes

12 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 3
rohitn62196663
Level 3

Likes

12 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
rohitn62196663
Level 3

04-10-2016

package com.xxx.totalinsight.components;

public class MiniNavBean {

    private String fPath;
    
    private String activeAttr;
    
    private String scpTitle;
    
    public MiniNavBean(String fPath, String activeAttr,  String scpTitle){
        
        this.fPath = fPath;
        this.activeAttr = activeAttr;
        this.scpTitle = scpTitle;
    }
    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;
    }

    public String getScptitle() {
        return scpTitle;
    }

    public void setScptitle(String scptitle) {
        this.scpTitle = scptitle;
    }
    

}

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

04-10-2016

Looking at your bean on your HTL expressions, they don't match...

you have .fPath and activeAttr

and you have getFpath() and getActiveattr()

 

 <p>fpath : ${navlist.fPath}</p>
 <p>activeAttr: ${navlist.activeAttr}</p>

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

05-10-2016

Avatar

Avatar
Validate 10
Level 3
rohitn62196663
Level 3

Likes

12 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 3
rohitn62196663
Level 3

Likes

12 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
rohitn62196663
Level 3

05-10-2016

Thanks a lot. It worked now. I was expecting it to work with the variable name itself,didnt know we need to call the getter too in sightly. To refer the linkedlist in sightly I didn't call any getter but I just called the navList object directly as "${mininav.navList}">. But dont know why do we need to call the getter for the variables in bean. 
     
Thanksa lot. It worked now. I was expecting it to work with the variable name itself,didnt know we need to call the getter in sightly. To refer the linkedlist in sightly I didn't call any getter but I just called the navList object directly. But dont know why do we need to call the getter for the variables in bean.