0

Sorry, I know this seems similar to other questions but I still can't work out the solution.

I have a LinkedHashMap<Long,ExperimentMetadata> metadata set as a session attribute. (ExperimentMetadata is a javabean.) I want to get an attribute from a specific bean whose key is the parameter metadata_key. But when I try to get this directly, e.g.

<c:out value="${metadata[param.metadata_key].name}" />

the result is blank.

However, when I iterate over the whole map it works fine e.g.

<c:forEach items="${metadata}" var="exp">
    <c:if test="${exp.key eq param.metadata_key}">
        <c:out value="${exp.value.name}" />
    </c:if>
</c:forEach>

Which I can do but it kind of defeats the purpose of using a hashmap. It also works if I do e.g.

<c:out value="${metadata[1].name}" />

Can anyone help suggest what the problem is and how to fix it? Thankyou!

Kate
  • 29
  • 2

1 Answers1

0

Hey I just figured it out! I think because metadata_key is a parameter, EL read it as a string not a long. Forcing it to think about numbers made it work, e.g.

<c:out value="${metadata[param.metadata_key*1].name}" />

I feel so proud. ;)

Kate
  • 29
  • 2