tags:

views:

273

answers:

1

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>
+2  A: 

The code you posted (and edited) is syntactically valid, so the problem lies somewhere else.

To start, the Id suffix makes me think it's actually a Number. Fact is, non-decimal numbers in EL defaults to long. Thus, if it were a Map<Integer, Integer>, then this code won't work. You need to have a Map<Long, Long> or Map<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.

BalusC
Thanks for that, it got me on the right track. Map is actually <String, String> and the templateId is BigDecimal. Regarding the coding horror. I have worked on various application of myriad complexities in my career. This one takes the cake... Everybody has to do dirty stuff once in a while... :)
AM01