Sightly Code to iterate over Map which is list of String - Does not work in 6.3 | Community
Skip to main content
Level 3
April 20, 2018

Sightly Code to iterate over Map which is list of String - Does not work in 6.3

  • April 20, 2018
  • 3 replies
  • 6790 views

Hi All,

We have sightly code which was working fine in 6.1 and stopped working in 6.3.

Code to iterate over Map which is a list of String.

Sightly (HTL)

<sly data-sly-use.table="${'my.models.Table'}">

     <div>

          <table data-sly-list.row="${table.rowList}">

               <tr data-sly-list.columnCell="${table.rowList[row]}">

                    <td>

                          ${columnCell}

                    </td>

               </tr>

          </table>           

     </div>

</sly>

       

Model Java:

Map<Integer,List<String>> myMap = new HashMap<Integer,List<String>>();

  

    for(int i=1;i<=3;i++)

    {

         List<String> list = new ArrayList<String>();

         list.add("" + i);

         list.add("" + i*i);

         list.add("" + i*i*i);

  

         myMap.put(new Integer(i-1),list);

    }

This sightly code stops working where ${table.rowList[row]} always returns null and hence inner loop does not execute.

Is there any change in 6.3 with respect to sightly where rowList[row] kind of notation is disabled ? Could not find something similar on google.

I also tried iterator way and passed the item in the array index. But that also does not solve the issue.

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

3 replies

RonakBAuthor
Level 3
April 23, 2018

The way I fixed it was by converting the Map key from Integer to String.

myMap.put(Integer.parseInt(i-1),list)

No change in Sightly component.

Not sure how this worked in 6.1 and not in 6.3.

kautuksahni​ / smacdonald2008​ : Have you heard about this type of issue before ?

RonakBAuthor
Level 3
April 29, 2018

And we were able to identify the same pattern for 2 other components and fix it in the same way.

Basically the array notation with square bracket is not working where the Model is returning HashMap(Interger,List<Object>).

kautuk_sahni
Community Manager
Community Manager
May 1, 2018

Can you quickly try with Map<Integer,String> myMap = new HashMap<Integer,String>(); ?

Kautuk Sahni
smacdonald2008
Level 10
May 1, 2018

See this artilce to learn how to work with HTL and Collections -- Scott's Digital Community: Creating a HTL Repeating Data Set 6.3 Component that uses Sling Models

RonakBAuthor
Level 3
May 10, 2018

Hi smacdonald2008​:

Thanks for the article but that uses a normal java collection and I have evidences in my code that this works fine.

The issue we are observing is especially when there is a key which is Integer object and in sightly we use [] notation. See my code above. This used to work fine in 6.1

smacdonald2008
Level 10
May 10, 2018

Can you show what you are doing in the Java code.