开发者

Accessing Map value in a separate JSTL loop

开发者 https://www.devze.com 2022-12-18 01:27 出处:网络
Assume that a query result exists called resultSet having a field available as templateId. Also, a map \'templateMap\' exists with keys of templatedId.

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:o开发者_JAVA技巧ut 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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消