Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #13125

Re: JSTL: getting a map's keys

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: JSTL: getting a map's keys
Date 2012-03-22 13:23 -0700
Organization http://groups.google.com
Message-ID <11405563.61.1332447814183.JavaMail.geo-discussion-forums@pbctp7> (permalink)
References (3 earlier) <9sruffF39oU1@mid.individual.net> <14359232.4616.1332266714833.JavaMail.geo-discussion-forums@pbcr5> <9sujq2Foc1U1@mid.individual.net> <jkfe8k$si4$1@news.albasani.net> <9t1791Fdo5U1@mid.individual.net>

Show all headers | View raw


Chris Riesbeck wrote:
> 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 [].

I was thinking along the lines of this incompletely worked-through notion:

 public class ContactScreenBacker
 {
   private final Map<String, Rate> rates = howeverYouSetItUp();
   public Map<String, Rate> getRates() { return Collections.unmodifiableMap(rates); }
   public Set<String> getKeys() { return Collections.unmodifiableSet(rates.getKeys(); }
// ...
 }

You should be able to use an EL like '#{thingie.rates["Bill"]}'. I haven't tried it, but this is what I had in mind.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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