java jsonarray to sightly data-sly-list aem | Community
Skip to main content
Level 4
Jun 28, 2018 1:17 PM UTC
Solved

java jsonarray to sightly data-sly-list aem

hi,

i am using aem 6.1

i have data in java jsonarray

is there any way to access jsonarray  to sightly in data-sly-list?

java looks like :

@Model(adaptables = Resource.class)

public class Details {

private JSONArray objList;

public JSONArray getList() {

        return objList;

    }

@PostConstruct

    private void functionName(){

objList=new JSONArray();

     //get value into objList; --which is working

}

}

html :

<sly data-sly-use.obj="${'com.abc.Details}" data-sly-unwrap>

     <sly data-sly-list.obj="${obj.objList}"></sly> --> not getting value here

</sly>

let me know if more details are required.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Jun 28, 2018 2:43 PM UTC

Your Issue is you are not calling the method (defined in the Sling Model Java class)  that returns the List. Assume we have this method - which returns a collection:

public List<Columns> getCol() {

        return col;

    }

To invoke it from HTL - we use: (the method is called by dropping get and simply the name of the remaining part of the getter method - in the case "col")

<div class="row">

    <div data-sly-list="${colControl.col}" data-sly-unwrap>

        <div data-sly-attribute="${item.clssAttr1}">

            <div data-sly-resource="${@ path='par_0', resourceType='foundation/components/parsys'}" data-sly-unwrap></div>

        </div>

        <div data-sly-attribute="${item.clssAttr2}">

            <div data-sly-resource="${@ path='par_1', resourceType='foundation/components/parsys'}" data-sly-unwrap></div>

        </div>

    </div>

</div>

See this AEM Community Article to learn how to work with Collections (List) and HTL so the data in the Collection is rendered in the component.

Creating a custom Touch UI Grid Component for Adobe Experience Manager

Hope this helps...

1 reply

smacdonald2008
smacdonald2008Accepted solution
Level 10
Jun 28, 2018 2:43 PM UTC

Your Issue is you are not calling the method (defined in the Sling Model Java class)  that returns the List. Assume we have this method - which returns a collection:

public List<Columns> getCol() {

        return col;

    }

To invoke it from HTL - we use: (the method is called by dropping get and simply the name of the remaining part of the getter method - in the case "col")

<div class="row">

    <div data-sly-list="${colControl.col}" data-sly-unwrap>

        <div data-sly-attribute="${item.clssAttr1}">

            <div data-sly-resource="${@ path='par_0', resourceType='foundation/components/parsys'}" data-sly-unwrap></div>

        </div>

        <div data-sly-attribute="${item.clssAttr2}">

            <div data-sly-resource="${@ path='par_1', resourceType='foundation/components/parsys'}" data-sly-unwrap></div>

        </div>

    </div>

</div>

See this AEM Community Article to learn how to work with Collections (List) and HTL so the data in the Collection is rendered in the component.

Creating a custom Touch UI Grid Component for Adobe Experience Manager

Hope this helps...

Translate