wood burning stoves 2.0
The moose likes JSF and the fly likes How to remove ArrayList<SelectItem> element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to remove ArrayList<SelectItem> element" Watch "How to remove ArrayList<SelectItem> element" New topic

How to remove ArrayList<SelectItem> element

sa sam
Ranch Hand

Joined: Mar 01, 2009
Posts: 46
i have ArrayList<SelectItem> class and i added items using

my problem is how can i remove item by name i.e. if i want to remove item from ArrayList<SelectItem> class whose name/label is "classA"
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

You have to use brute force, enumerate the SelectItem list until you find a match, then do a list.remove() operation on that SelectItem. It's not something that's common enough to mandate an API method of its own and it's not something complicated enough to be worth inflating the core JSF library over. I write a generic search/remove method for the one webapp I've got that does that kind of stuff and use it for al the SelectItem lists.

As long as the list is less than about 20 items, fancier search techniques don't actually help that much. And, as a general rule, you want to keep dropdown lists reasonably short or the users may decide to come and kill you.

An IDE is no substitute for an Intelligent Developer.
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Sorry to resurrect an old thread...

If you have a SelectManyListbox, and you want to remove one or multiple selectItems, another option is to use a nested for loop.

As you know a SelectManyListbox uses a List for the SelectItems and possibly a String array (or collection or map) for the values in the listbox.

The outer for loop would be the length of the selected items in the list box, the inner for loop would be the size of the items in the listbox. Match the inner loop value to the outer loop value and remove the inner loop value at the inner loop index. (clear as mud, right?).

Thanks, leo
I agree. Here's the link: http://aspose.com/file-tools
subject: How to remove ArrayList<SelectItem> element
It's not a secret anymore!