Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL: Maps and static properties  RSS feed

 
Eric Savage
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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:
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!