Right, that's just not gonna happen with JSTL's EL. Well, I suppose you could
keep a "shadow" map that mapped values to keys, but that seems like a
management headache as well as a bit of session bloat. With JSP 2.0, you could
create an EL function to do it, but you're out of luck with JSP 1.2/JSTL 1.0.
Even programmatically, there's no straightforward method for getting the key of
a mapped value. You basically have to iterate through the entries looking for a
mapping that contains a value equal to one you're holding. You may want to
investigate writing a custom taglib for this if you really need this
functionality in a JSP. Other options are to use a Filter or Servlet (or a
controller component if you're using an MVC framework) to search for the key
and then set it as a request attribute for the JSP to use.

Quoting Adrian Beech <[EMAIL PROTECTED]>:

> G'day,
> 
> Ummmmmm, this returns the value associated with the key... I need to do the
> opposite whereby I have the value and I need it's key.
> 
> Thanks.
> AB
> 
> -----Original Message-----
> From: Tim Troy [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, 9 October 2004 10:33 PM
> To: [EMAIL PROTECTED]
> Subject: FW: [JSTL] Retrieving the key from a LinkedMap for a known value?
> 
> 
> I have a bean with a HashMap named errorCodes.  To access a key using jstl,
> I do the following:
> 
> <c:out value="${bean.errorCodes['categoryId']}"></c:out>
> 
> -----Original Message-----
> From: Adrian Beech [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, October 09, 2004 1:59 AM
> To: 'Tag Libraries Users List'
> Subject: [JSTL] Retrieving the key from a LinkedMap for a known value?
> 
> 
> G'day all,
> 
> Is it possible to retrieve the key from a LinkedMap for a known value using
> the expression language syntax under JSTL 1.0?
> 
> For example, I have a LinkedMap object which is being used to generate a
> drop down with the <input:select .../> tag from the Input taglib.  Apart
> from needing the value selected by the user from the drop down I need to
> pull the corresponding key for display purposes on the next page along in
> the food chain.  As I've already got the key/value pairs in a LinkedMap
> within the session context I was hoping to merely say "well here is the
> value from the drop down now give me the key which was used as the display
> text for that drop down".  
> 
> Does this sort of make sense?
> 
> AB

-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

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

Reply via email to