That's an odd little wrinkle to the EL ;-). For a test, I put together a JSP:

<%@ page contentType="text/plain" %>
<%@ taglib prefix="c" uri=""; %>

<jsp:useBean id="map" class="java.util.HashMap"/>

map.put(new Integer(1), "One");
map.put(new Integer(2), "Two");
map.put(new Integer(3), "Three");

pageContext.setAttribute("two", new Integer(2));

<c:set var="twoValue" value="${2}"/>
<c:set var="twoString" value="2"/>

'<c:out value="${map[two]}"/>'
'<c:out value="${map[2]}"/>'
'<c:out value="${map['2']}"/>'
'<c:out value="${map[twoValue]}"/>'
'<c:out value="${map[twoString]}"/>'

Here's the output:


So, if you've already got a key as a scoped attribute, you're okay. Otherwise, I don't see how to get JSTL to deal with it. Anyone else have any insight?

N. Chen wrote:
I believe you can do (with reportID a variable containing the key)
<:set var="laborReport" value='${mapOfLaborReports[reportID]}'/>

which is very different from (with "reportID" as the key)
<:set var="laborReport" value='${mapOfLaborReports["reportID"]}'/>

so to use 3 as a key
<c:set var="laborReport" value='${mapOfLaborReports["3"]}'/>

On 16 Jul 2003, Rick Reumann wrote:

There is probably a real easy answer for these two questions, but I
searching the archives for a while hasn't helped...

1) I have beans in a map that are stored with integers for the keys.

For testing I can retrive the bean out fine with the key of "test" like:

<c:set var="laborReport" value="${mapOfLaborReports.test}"/>

But if I try this with...

<c:set var="laborReport" value="${mapOfLaborReports.3}"/>

I get a parsing error:

4: tag = 'set' / attribute = 'value': An error occurred while parsing
custom action attribute "value" with value "${mapOfLaborReports.3}":
Encountered ".3", expected one of ["}", ".", ">", "gt", "<", "lt", "==",
"eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/",
"div", "%", "mod", "and", "&&", "or", "||", ":", "("]

2) Also, is there a way that I can some how nest my expressions? In
other words say "test" is the value of a parameter with the name
"reportID" in scope. Now in the first example I'd like to be able to do
something like...

<:set var="laborReport" value="${mapOfLaborReports.${reportID}}"/>

(Tied into the first question reportID is an Integer but if need be I
can make sure it's a String representation of the Integer).

Thanks for any help.


-- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <>

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to