0

This is my java code which creates a multidimensional hashmap:

HashMap<String, HashMap<String, String>> data = new HashMap<String, HashMap<String, String>>();

for (App app : apps) {
    String randomVar = "";

    data.put(String.valueOf(app.getId()), new HashMap<String, String>());
    data.get(String.valueOf(app.getId())).put("name", app.getName());
    data.get(String.valueOf(app.getId())).put("info", randomVar);
}

This is my .jsp file:

<c:forEach items="${data}" var="items">
    <c:forEach items="${items}" var="item">
        <div class="col-md-6">
            <div class="overview">
                <a href="/goto/${items.key}" class="minimal" title="Switch to: ${item.name}">
                    ${item.randomVar}
                    <span>${item.name}</span>
                </a>
            </div>
        </div>
    </c:forEach>
</c:forEach>

Unfortunately, I can't make the loop in the jsp file work. The problem is with the second loop. I can't reach the variables. Whatever I try, I get errors like Don't know how to iterate over supplied 'items' in <forEach> or that items.name doesn't exist and so on. How can I properly loop the hashmap?

Jordy
  • 4,719
  • 11
  • 47
  • 81

1 Answers1

1

Shouldn't it be items="${items.value}?

Maurice Perry
  • 9,261
  • 2
  • 12
  • 24
  • That gives me this error: `javax.el.PropertyNotFoundException: Property 'name' not found on type java.util.HashMap$Node` – Jordy Aug 28 '17 at 13:13
  • @Jordy yes, it's also `${item.key}` instead of `${item.name}` and `${item.value.name}` and `${item.value.info}` – Maurice Perry Aug 28 '17 at 13:37
  • @Jordy no, `${item.key} ` will have 'name' and 'info', `${item.value}` will have app.getName() and randomVar (but of course, `${item.name}` and `${item.randomVar}` don't exist). – Maurice Perry Aug 28 '17 at 13:44