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

Avatar

Avatar

RonakB

Avatar

RonakB

RonakB

19-04-2018

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.

Replies

Avatar

Avatar

RonakB

Avatar

RonakB

RonakB

22-04-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 ?

Avatar

Avatar

RonakB

Avatar

RonakB

RonakB

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

Avatar

Avatar

kautuk_sahni

Community Manager

Total Posts

5.7K

Likes

1.0K

Correct Reply

1.1K

Avatar

kautuk_sahni

Community Manager

Total Posts

5.7K

Likes

1.0K

Correct Reply

1.1K
kautuk_sahni
Community Manager

01-05-2018

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

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

01-05-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

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

01-05-2018

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

Avatar

RonakB

Avatar

RonakB

RonakB

09-05-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

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

10-05-2018

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