• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Struts tag to obtain size of a Collection

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How am I supposed to check whether the size of an array list in session, (say arrayList) is greater than zero or not using <logic: tag?
eg:<logic:greaterThan name="arrayList property="???" value="0">
// Something
</logic:greaterThan>

What is the property tag going to hold?
Plz help.
regards,
Sam.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sam,
Since all Collection implementors have size() and isEmpty() methods that yield the info you need, you can start there. If you only want to check if the Collection has elements, you can use:

OR

Both of these will use the isEmpty() method on the Collection to determine the logic return.
I typically use a transfer object over the Collection class and add helper methods like getSize(), isPlural(), etc. In that case a simple logic tag can check the size more precisely:

HTH,
--
Josh
 
rubbery bacon. rubbery tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic