Expand my Community achievements bar.

Sightly:How to iterate Map<String, Map<String, Map<ModelObject, List<ModelObject>>>>

Avatar

Level 2

Hi All,

I am not able to iterate the below map in sightly.

Map<String, Map<String, Map<ModelObject, List<ModelObject>>>>

I want to parse this map and read all the elements in all objects.

Please help.

7 Replies

Avatar

Administrator

Did you chek this post: Sightly : How to Iterate through Map&lt;String , Map&gt;

//Here an example the shows how it can be done, without java code.

  https://github.com/heervisscher/htl-examples/blob/master/core/src/main/java/com/adobe/examples/htl/c...

HTL-code:

<div data-sly-use.hashmap="com.adobe.examples.htl.core.hashmap.HashMapExample"

     data-sly-list="${hashmap.map.keySet.iterator}">

     ${item}

     <ul data-sly-list.aem="${hashmap.map[item].keySet.iterator}">

         <li>${aem} ${hashmap.map[item][aem]}</li>

     </ul>

</div>

Another post List of maps in Sightly

Helpx https://helpx.adobe.com/experience-manager/using/htl_movie62.html

~kaututk



Kautuk Sahni

Avatar

Level 2

Yes I checked this post and I am able to iterate but I am not able to iterate this below mentioned part of map.

Map<ModelObject, List<ModelObject>>

I am able to get key of above map, but I am not able to get value which is list of model object.

Avatar

Level 10

Kautuk pointed you to valid code to iterate collections. Also see this article for another example:

Adobe Experience Manager Help | Creating an Adobe Experience Manager HTL component that displays a r...

This HTL component works with a Collection as well. For your example, make sure that you correctly reference the element in the collection using correct HTL syntax.

Avatar

Level 2

Hi Smacdonald,

Kautuk pointed to iterate collections is correct.But in my collection while iterating last map I am able to get key which is object but I am not able to get value corresponding to object key.

I am getting invalid property name error.

Need help with the last map iteration.

Avatar

Level 2

Hi Feike,

PFB sightly code.

<ul role="menu" aria-expanded="false" aria-hidden="true" data-sly-list.outer="${modelClass.map[key][keyName].keySet.iterator}"

                                    data-sly-test="${modelClass.map[key][keyName].keySet.iterator}">

                     <li class="has-sub closed" role="menuitem">

                       <span>${outer.mainTitle}</span>

  <ul role="menu" aria-expanded="false" aria-hidden="true" data-sly-test="${modelClass.map[key][keyName][outer]}">

                      </ul>

                   </li>

</ul>

I am getting invalid property name error while testing last  iteration <ul> tag.

Avatar

Community Advisor

Can you share a package with the sample code to replicate this issue and test it out to find the root cause ?