• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Getting size of an array thru EL

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Can we get a size of an array by using EL? Or, using scriptlet is the only way to get it, when constructing a JSP?

regards,
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great question.

EL expects objects to abide by Bean Law. But some of our most common Java classes don't follow the rules: String.length(), *Arrays*.length, and the Collection classes.size().

It's likely that your collection/array/string exists in a bean, whether you are keeping it in a Struts ActionForm or just a plain ol' Transfer Object. That means you can add a method to your bean for retrieving size of these items.

An example is given here, and yes it does seem "kludgy".
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yes, and as Satou mentions here, you can use fn:length as long as you are working with J2EE 1.4. Here's a decent Sun tutorial on how to use it.

The "kludgy" way is for 1.3, which you may end up having to implement in the real world. The entire world isn't using 1.4 yet and you have to make do with whatever you've got. :roll:
 
Varun Ratra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marc,

Thanks a lot for your help.

regards,
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marc,

How about having a generic static utility function, say getLength(Object) in some utility class which will return the size of the collection/array/String ?



This function can be registerd in a tld flle and could be invoked from the jsp using EL.


Sounds decent...doesnt it ? :-)

Cheers,
Arvind
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic