File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSTL forEach tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSTL forEach tag" Watch "JSTL forEach tag" New topic

JSTL forEach tag

Sakhi Karani

Joined: Jun 05, 2009
Posts: 4
Hi, Can I use forEach tag with HashSet in items attribute? I am using JSF 1.2 and adding forEach JSTL tag to iterate over the items and display each item in a tab. My backing bean gives me a HashSet in the items attribute. I tried to do it, but my richfaces tab label fails but if I use ArrayList in place of HashSet then everything works fine, along with richfaces.
Where am I going wrong? Please help.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

Please be sure to ask JSF questions in the JSF forum. I have moved this post there for you.

[Asking smart questions] [About Bear] [Books by Bear]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

Karani Karani wrote:
Where am I going wrong? Please help.

You're going wrong because you're attempting to sequence through a set of non-sequential data, I think. Easiest way around that is to add a property getter to your backing bean that returns the toArray() method called on the HashSet. However be prepared to see things move around unpredictably if you add or remove elements from the underlying HashSet. If that's not acceptable, you need to trade in your vanilla Set object for something that has a predictable ordering (for example, implements the Comparable interface on ts elements).

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: JSTL forEach tag
It's not a secret anymore!