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

SOLVED

java jsonarray to sightly data-sly-list aem

kiranc13433869
Level 4
Level 4

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.

1 Accepted Solution
smacdonald2008
Correct answer by
Level 10
Level 10

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...

View solution in original post

1 Reply
smacdonald2008
Correct answer by
Level 10
Level 10

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...

View solution in original post