This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts tag to obtain size of a Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts tag to obtain size of a Collection" Watch "Struts tag to obtain size of a Collection" New topic
Author

Struts tag to obtain size of a Collection

Sam Drake
Ranch Hand

Joined: Jun 05, 2003
Posts: 33
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.
Josh Landin
Greenhorn

Joined: Jun 09, 2003
Posts: 10
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
 
Don't get me started about those stupid light bulbs.
 
subject: Struts tag to obtain size of a Collection
 
Similar Threads
LogicGreaterThan tag
nested logic:iterate tags possible?
Passing parameters
struts2 question
tag nesting error?