Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

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

Avatar

Level 3

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.

7 Replies

Avatar

Level 3

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 ?

Avatar

Level 3

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

Avatar

Administrator

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



Kautuk Sahni

Avatar

Level 10

Actually the above article - shows use of Sling Models and a Multi-field. Its useful but does not show use of a Java collection. See this 6.2 artilce where we use WCMUSePojo and show use of a Java collection in the Java code and how to render the values: Adobe Experience Manager Help | Creating an Adobe Experience Manager HTL component that displays a r...

Avatar

Level 3

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

Avatar

Level 10

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