This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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
reply
    Bookmark Topic Watch Topic
  • New Topic