Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13080
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed0.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Chris Riesbeck <Chris.Riesbeck@gmail.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: JSTL: getting a map's keys |
| Date | Tue, 20 Mar 2012 12:19:42 -0500 |
| Lines | 51 |
| Message-ID | <9srshfFjo5U1@mid.individual.net> (permalink) |
| References | <9spbepF1baU1@mid.individual.net> <xLP9r.4373$dq4.2106@newsfe23.iad> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net OoOpzm8DZQJMv8Brwsa05gZZsXnuGb8TLljY43BJbih2wZQW3n |
| Cancel-Lock | sha1:lkU46EFcu+STRF91W3netHE8y0Y= |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 |
| In-Reply-To | <xLP9r.4373$dq4.2106@newsfe23.iad> |
| Xref | csiph.com comp.lang.java.programmer:13080 |
Show key headers only | View raw
On 3/19/2012 6:59 PM, Daniel Pitts wrote:
> On 3/19/12 11:15 AM, Chris Riesbeck wrote:
>> Can anyone help me figure out why the following is happening, or further
>> experiments I can run? (I have workarounds but I'd like to know what I'm
>> misunderstanding.)
>>
>> Given:
>> - SimTable, a subclass of HashTable that defines getKeys() to call
>> keyset()
>> - a session variable "data" which is a HashTable with "rates" set to an
>> instance of a SimTable
>>
>> Why does ${rates.keys} generate nothing in these lines of JSP?
>>
>> <c:set var="rates" value='${data["rates"]}'/>
>>
>> <p>rates: ${rates}</p>
>>
>> <p>jstl: ${rates.keys}</p>
>>
>> <p>jsp: <%= ((edu.northwestern.ils.simulator.SimTable)
>> pageContext.findAttribute("rates")).getKeys() %></p>
>>
>> Here's the generated HTML output:
>>
>> <p>rates: {Bill=100.0, Fred=75.0, Jane=75.0, Mary=50.0, Sam=75.0,
>> Sarah=150.0}</p>
>>
>> <p>jstl: </p>
>>
>> <p>jsp: [Bill, Fred, Jane, Mary, Sam, Sarah]</p>
>>
> My guess is that ${rates.keys} is interpreted as equivalent to
> ${rates['keys']}, so it is looking for a key of "keys", not a java bean
> property.
Ah! This would explain why ${rates.class} doesn't work either.
Basically, name.key will always be taken as name[key] for a Map, even if
key is a property of name. If I'm reading the JSP EL resolver
specification correctly, that's just what is happening.
>
> You *can* use c:forEach to iterate over the entry set (Map.Entry) in a map.
Yes, that's what I've been doing instead for looping.
>
> Hopefully this helps,
> Daniel.
Indeed. Thanks, Daniel
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
JSTL: getting a map's keys Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2012-03-19 13:15 -0500
Re: JSTL: getting a map's keys Lew <lewbloch@gmail.com> - 2012-03-19 12:57 -0700
Re: JSTL: getting a map's keys Tim Slattery <Slattery_T@bls.gov> - 2012-03-19 16:08 -0400
Re: JSTL: getting a map's keys Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2012-03-19 16:06 -0500
Re: JSTL: getting a map's keys Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2012-03-19 16:39 -0500
Re: JSTL: getting a map's keys markspace <-@.> - 2012-03-19 15:27 -0700
Re: JSTL: getting a map's keys Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-19 16:59 -0700
Re: JSTL: getting a map's keys Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2012-03-20 12:19 -0500
Re: JSTL: getting a map's keys Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2012-03-20 12:52 -0500
Re: JSTL: getting a map's keys Lew <lewbloch@gmail.com> - 2012-03-20 11:05 -0700
Re: JSTL: getting a map's keys Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2012-03-21 13:09 -0500
Re: JSTL: getting a map's keys Lew <noone@lewscanon.com> - 2012-03-22 07:51 -0700
Re: JSTL: getting a map's keys Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2012-03-22 12:53 -0500
Re: JSTL: getting a map's keys Lew <lewbloch@gmail.com> - 2012-03-22 13:23 -0700
Re: JSTL: getting a map's keys Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2012-03-23 12:23 -0500
Re: JSTL: getting a map's keys Lew <noone@lewscanon.com> - 2012-03-23 13:50 -0700
Re: JSTL: getting a map's keys Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2012-03-26 14:10 -0500
Re: JSTL: getting a map's keys Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-20 11:28 -0700
Re: JSTL: getting a map's keys markspace <-@.> - 2012-03-20 11:29 -0700
Re: JSTL: getting a map's keys Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-20 12:10 -0700
csiph-web