tags:

views:

165

answers:

1

Hi, I have the following code on my jsp page:

<c:out value="${items}" /><br />

<c:forEach items="${items}" var="item">
     1. <c:out value="${item.key}" /><br />
     2. <c:out value="${item.key eq 70}" /><br />
     3. <c:out value="${items[70]}" /><br />
     4. <c:out value="${items[item.key]}" /><br />
</c:forEach>

And it produces the following output

{70=true}
1. 70
2. true
3.
4. true

And I just can't figure out why 3. is empty. Any ideas?

The map is of type Map<Integer, Boolean>

+2  A: 

Basically autoboxing puts an Integer object into the Map. ie: map.put(new Integer(0), "myValue")

EL evaluates 0 as a Long and thus goes looking for a Long as the key in the map. ie it evaluates: map.get(new Long(0))

As a Long is never equal to an Integer object, it does not find the entry in the map. Thats it in a nutshell.

Refer forum http://forums.sun.com/thread.jspa?messageID=9702932#9702932

valli
That explains it then, thanks.
Solution: use `Map<Long, Boolean>` instead.
BalusC