Iterate Multivaluedmap in sightly

Avatar

Avatar

nithyakri18

Avatar

nithyakri18

nithyakri18

23-12-2020

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>

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Manjunath_K

Avatar

Manjunath_K

Manjunath_K

23-12-2020

Hi @nithyakri18 ,

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!

Answers (2)

Answers (2)

Avatar

Avatar

nithyakri18

Avatar

nithyakri18

nithyakri18

24-12-2020

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>

Avatar

Avatar

praveenjain

Avatar

praveenjain

praveenjain

24-12-2020

 

 

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