• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to remove ArrayList<SelectItem> element

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
 
Saloon Keeper
Posts: 27885
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?).
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic