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 Newsgroups: comp.lang.java.programmer Subject: Re: JSTL: getting a map's keys Date: Mon, 19 Mar 2012 16:39:31 -0500 Lines: 97 Message-ID: <9spnckF2cdU1@mid.individual.net> References: <9spbepF1baU1@mid.individual.net> <2b4fm7t90armrhn9qjn7qi25oqssceja73@4ax.com> <9sple1FilsU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net dcd5K23X9x3aLp/QiRLUIQfOImkqXZqC/HflfnobMPyQ37x2QE Cancel-Lock: sha1:/urjutrM3+ti0hwJwIdKFfZDRaM= User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: <9sple1FilsU1@mid.individual.net> Xref: csiph.com comp.lang.java.programmer:13060 On 3/19/2012 4:06 PM, Chris Riesbeck wrote: > On 3/19/2012 3:08 PM, Tim Slattery wrote: >> Chris Riesbeck wrote: >> >> >>>

jstl: ${rates.keys}

>> >> The EL here finds the object "rates" and looks for an attribute named >> "keys". That means that if rates doesn't have a public method named >> getKeys, the EL won't find anything. >> > Which it does. Here's a complete example, class and test JSP, and the > HTML output I get > > ****** CLASS > > package example; > > import java.util.HashMap; > import java.util.Set; > > public class SimTable extends HashMap { > > public Set getKeys() { > return keySet(); > } > } > > ****** JSP > > <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> > > <% > final example.SimTable data = new example.SimTable(); > data.put("Bill", 100); data.put("Mary", 150); data.put("Fred", 200); > pageContext.setAttribute("data", data); > %> > > > > > Test > > >

data: ${data}

>

data.keys: ${data.keys}

>

data.getKeys(): > <%= ((example.SimTable) pageContext.findAttribute("data")).getKeys() %> >

> > > > > ****** HTML output > > > > > Test > > >

data: {Bill=100, Mary=150, Fred=200}

>

data.keys:

>

data.getKeys(): > [Bill, Mary, Fred] >

> > > And I added these lines to my JSP to see if "keys" was appearing as a property via the Introspector and it was ****** additional JSP
  • ${prop.name}
****** additional HTML output
  • class
  • empty
  • keys