How do I iterate through a map that has value, Map<String,Integer> declared as Map<String,Map<String,Integer>>using Expression Language ?

StackOverflow https://stackoverflow.com/questions/22582917

  •  19-06-2023
  •  | 
  •  

Question

I'm new to this and am not sure how to proceed. I need to populate the String-Integer map's key in select once I figure how to display it. So far I tried the following code but failed.

<c:forEach var="entry" items="${perCat}">
<c:out value="${entry.key}"></c:out>
</c:forEach>

The above code displays the String key of the Map- However, I don't know how to display the key-values of the second Map

Tried this:/

<c:forEach var="entry" items="${myMap}">
<c:out value="${(entry.value).key}"/>
</c:forEach>
Was it helpful?

Solution

You've to iterate over the values too, as you did for the outer map:

<c:forEach var="entry" items="${perCat}">
    <c:out value="${entry.key}"></c:out>
    <c:forEach var="valueEntry" items="${entry.value}">
        <c:out value="${valueEntry.key}" /> 
        <c:out value="${valueEntry.value}" />
    </c:forEach>
</c:forEach>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top