Assume that a query result exists called resultSet having a field available as templateId.
Also, a map ‘templateMap’ exists with keys of templatedId.
I am not able to get any result from the following, any help appreciated.
<c:foreach var="row" items="${resultSet.rows}">
<c:out value="${templateMap[row.templateId]}" />
</c:foreach>
Note: this is a coding horror application, wherein the above resultset is a result of <sql:query>.
Following doesn’t work either.
<c:foreach var="row" items="${resultSet.rows}">
<c:set var="tmplId" value="${row.templateId}" />
<c:out value="${templateMap[tmplId]}" />
</c:foreach>
The code you posted (and edited) is syntactically valid, so the problem lies somewhere else.
To start, the
Idsuffix makes me think it’s actually aNumber. Fact is, non-decimal numbers in EL defaults tolong. Thus, if it were aMap<Integer, Integer>, then this code won’t work. You need to have aMap<Long, Long>orMap<Long, Integer>to get it to work.I am not sure how I should interpret your wording “coding horror application”, but I bet that you already know that using JSTL SQL taglib for other purposes than quick prototyping is considered a very bad practice 😉 That logic belongs in real Java classes in the data access layer.