views:

88

answers:

1

I am trying to access the first element of a TreeMap, I have the following HTML in a JSP file:

<c:forEach items="${subscriber.depent}" var="entry" begin="0" end="0" step="1">
    <c:set var="dep" value="${entry.value}" />
</c:forEach>

This code gets me the first element of the TreeMap but this just seems like a 'hack' to me.

I have also tried:

<c:set var="dep" value="${subscriber.depent[0]}" />

But that gives me a exception:

java.lang.Integer incompatible with java.lang.Long

Any better ways of doing this?

Thanks, Randall.

+1  A: 

In order to do this, you need to get into a situation where the "first of" makes sense in the Collection/array/getter context that you have with JSTL. Unfortunately the TreeMap.firstKey is not a getter so you cannot get to it with JSTL-syntax.

If you can subclass the TreeMap you can add a "getFirstKey()" method which just calls firstKey and then refer to it with "subscriber.depent.firstKey".

Thorbjørn Ravn Andersen