Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!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: Thu, 22 Mar 2012 12:53:36 -0500 Lines: 33 Message-ID: <9t1791Fdo5U1@mid.individual.net> References: <9spbepF1baU1@mid.individual.net> <9srshfFjo5U1@mid.individual.net> <9sruffF39oU1@mid.individual.net> <14359232.4616.1332266714833.JavaMail.geo-discussion-forums@pbcr5> <9sujq2Foc1U1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net OdaMLj7Q4Rf7aRC2wzvf5QM826AOLTBw/3yQN1Oaj4e3z95nBQ Cancel-Lock: sha1:/DNdcBYd8KGYoywy9VJrClUQVQw= User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20120312 Thunderbird/11.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:13123 On 3/22/2012 9:51 AM, Lew wrote: > Chris Riesbeck wrote: >> Lew wrote: >>> - If you had *composed* a 'Map' into a custom class rather than >>> inheriting 'Map', you would not have had the problem. Your custom >>> class would have been resolved by the bean resolver. - This in turn >>> would make for a better design overall. Instead of your view artifact >>> (the JSP) caring about the implementation details of the map and its >>> set of keys, you'd have a controller call like 'getKeys()' or >>> whatever that would cleanly separate the logic of how you get them >>> from presentation concerns. >> >> Using delegation (my preference also) doesn't support the JSP EL form >> ${rates["Bill"]}. If I had a custom class, I'd need a custom tag or >> custom EL >> resolver to make that work. > > No, you most certainly would not. > > Just define an appropriate method in your class. Color me totally dense. Maybe I'm missing what method I should be defining. If my class implements the Map interface, then MAPElResolver will be invoked and do the same thing with name.key and name["key"]: call name.get("key"). The JSP EL won't be able to call any bean method of name. If my class doesn't implement Map, then BeanELResolver will be invoked and do the same thing with name.key and name["key"]: call name.getKey(). The JSP EL won't be able to call name.get() via []. So I don't see how I can have a class such that in the JSP EL I can call a method to get all the keys, and also retrieve data with a key using [].