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

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

Iterate Multivaluedmap in sightly

Avatar

Level 2

I am trying to iterate a multivaluedmap 

MultiValuedMap<String, Map<String,List<ModelObj>>> through HTL as below. But, I get values upto two levels which are String. Not able to access ModeObj. 

<div data-sly-use.nav="fragmentexamples.core.models.Nav">
<ul data-sly-list.year="${nav.map}">
<div> ${year} </div> ------ First level String gets printed
<ul data-sly-list.type="${year}">
<li>${type} </li> --------Second level String gets printed
${nav.map[year][type]} or ${nav.map[year][type]['modelObjProp']}------- not working
</ul>
</ul>
</div>

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Nithyasri_K ,

Try with below code snippet, refer map.entries & map.entrySet to iterate over MultiValuedMap & Map obejcts as mentioned below in data-sly-list.

 

<ul data-sly-list.yearsMap="${nav.map}">
<div> ${yearsMap.key} </div> ------ First level String gets printed
<ul data-sly-list.typesMap="${yearsMap.value.entrySet}">
<h1>${typesMap.key} </h1> --------Second level String gets printed

<sly data-sly-list.modelObjList="${typesMap.value}"> --------Second level Value Object List gets printed
<!--p>${modelObjList.attributeName}</p-->
</sly>
</ul>
</ul>

 

Hope this helps!

0 Replies

Avatar

Correct answer by
Community Advisor

Hi @Nithyasri_K ,

Try with below code snippet, refer map.entries & map.entrySet to iterate over MultiValuedMap & Map obejcts as mentioned below in data-sly-list.

 

<ul data-sly-list.yearsMap="${nav.map}">
<div> ${yearsMap.key} </div> ------ First level String gets printed
<ul data-sly-list.typesMap="${yearsMap.value.entrySet}">
<h1>${typesMap.key} </h1> --------Second level String gets printed

<sly data-sly-list.modelObjList="${typesMap.value}"> --------Second level Value Object List gets printed
<!--p>${modelObjList.attributeName}</p-->
</sly>
</ul>
</ul>

 

Hope this helps!

Avatar

Level 4

 

 

To handle Map<String, Map<String,List<ModelObj>>>, try below code:

<div data-sly-use.nav="fragmentexamples.core.models.Nav">
<ul data-sly-list.year="${nav.map}">
<div> ${year.key} </div> ------ First level String gets printed
<ul data-sly-list.type="${year.value}">
<li>${type.key} </li> --------Second level String gets printed
<ul data-sly-list.modelObj="${type.value}">
${modelObj.modelObjProp}
</ul>
</ul>
</ul>
</div>

Regards
Praveen

 

Avatar

Level 2

Hi @Manjunath_K 

 

Thank your for the help. Your solution worked with a slight modification as per my object.

 

<div data-sly-use.nav="fragmentexamples.core.models.Nav">
<ul data-sly-list.year="${nav.map.entrySet}">
<div> ${year.key}</div>
<ul data-sly-list.val="${year.value}">
<ul data-sly-list.type="${val.entrySet}">
<li>${type.key}
<ul data-sly-list.modelList="${type.value}">
<li>{modelList.modelProp}</a></li>
</ul>
</li>
</ul>
</ul>
</ul>
</div>