• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

JSTL: Maps and static properties

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two questions.
First, in JSTL, how does one get the size of a map/collection/etc. This seems such a common thing that I'm sure it must be somewhere but I can't find it. Following is my best guess, which returns nothing.

User.getTickets() returns a Hashtable. I also tried extending Hashtable and adding the following:

Doing scriptlets works fine, like:


Second, how does one reference a static property in JSTL. Something like the following:
 
Author
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eric Savage:
Two questions.
First, in JSTL, how does one get the size of a map/collection/etc. This seems such a common thing that I'm sure it must be somewhere but I can't find it.


Actually, JSTL 1.0 doesn't provide this; JSTL 1.1 will most likely introduce a function to support it.
In the meantime, you can either (a) provide a wrapper class with methods like getSize() and getArray(), or (b) simply loop over the array and compute its size with <c:forEach>'s 'varStatus' attribute. However, the latter option isn't particularly efficient.


User.getTickets() returns a Hashtable. I also tried extending Hashtable and adding the following:


A wrapper class will work in general, but an object's nature as a Map occludes its nature as a JavaBean for JSTL's purposes. That is, when an object is a Map, only its Map elements -- not its JavaBean properties -- will be returned.

[/QB]
Second, how does one reference a static property in JSTL. Something like the following:
[/QB]


[/QB]
The EL is intended only to refer to instance variables, not static data. You could expose a bean that returns the right values for particular constants, or use context-initialization parameters defined in web.xml.
 
Eric Savage
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now THAT is what I call a response. Thanks very much. I'm going to have to check out your book next time I'm at the store...
 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In regards to Shawn's response:


Actually, JSTL 1.0 doesn't provide this; JSTL 1.1 will most likely introduce a function to support it.



Has a function to get map size been introduced yet?

Thanks.

TJ
 
reply
    Bookmark Topic Watch Topic
  • New Topic