Iterate Multivaluedmap in sightly

Avatar

Avatar
Give Back
Level 1
Nithyasri_K
Level 1

Likes

2 likes

Total Posts

13 posts

Correct reply

0 solutions
Top badges earned
Give Back
Validate 1
Boost 1
View profile

Avatar
Give Back
Level 1
Nithyasri_K
Level 1

Likes

2 likes

Total Posts

13 posts

Correct reply

0 solutions
Top badges earned
Give Back
Validate 1
Boost 1
View profile
Nithyasri_K
Level 1

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
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile
Manjunath_K
MVP

23-12-2020

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!

Answers (2)

Answers (2)

Avatar

Avatar
Give Back
Level 1
Nithyasri_K
Level 1

Likes

2 likes

Total Posts

13 posts

Correct reply

0 solutions
Top badges earned
Give Back
Validate 1
Boost 1
View profile

Avatar
Give Back
Level 1
Nithyasri_K
Level 1

Likes

2 likes

Total Posts

13 posts

Correct reply

0 solutions
Top badges earned
Give Back
Validate 1
Boost 1
View profile
Nithyasri_K
Level 1

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
Give Back 5
Level 4
praveenjain
Level 4

Likes

37 likes

Total Posts

36 posts

Correct reply

10 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 5
View profile

Avatar
Give Back 5
Level 4
praveenjain
Level 4

Likes

37 likes

Total Posts

36 posts

Correct reply

10 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 5
View profile
praveenjain
Level 4

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