Yesterday N. Chen was kind in helping me with question I had concerning pulling a bean from a Map where the key is an Integer. Sorry, I don't have the original post here at work so I have to start a new thread.
The solution provided works great if the key in the map is a String, but I still can't get it to work when the key is an Integer. For example trying to do the following will work fine if the Map uses a String "3" for the key, but doesn't work when 3 as an Integer is used for the key... <c:set var="laborReport" value='${mapOfLaborReports["3"]}' /> <c:out value="${laborReport.conceptId}"/> I also have a request variable in scope called "currentLaborReportLevel" which has as its value an Integer. Ideally I'd like to be able to do as N. Chen helped me with... <c:set var="laborReport" value='${mapOfLaborReports[currentLaborReportLevel]}' /> But this also only seems to work when currentLaborReportLevel is a String and the mapOfLaborReports keys are stored as Strings. I understand that there are other ways I can accomplish what I need to do without using the Map on the page, and I'm leaning towards doing it that way, but I would be interested to know if this could be done. Thanks. The reply and original message which I have a copy of is below... Date: Wed, 16 Jul 2003 16:50:05 -0700 (PDT) From: "N. Chen" <[EMAIL PROTECTED]> To: Tag Libraries Users List <[EMAIL PROTECTED]> Subject: Re: How to retrieve a value from a Map where key is an Integer & ..? 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"]}'/> nick 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. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]