0

Is it possible to choose only specific items from the list in selectOneMenu? For example. I have List Products has many fields like name, id etc. One of it is category (1,2 or 3) I want to have only one category in the selectOneMenu without making new Lists and new classes. Can you help me?

Mateusz Gaweł
  • 673
  • 1
  • 8
  • 22

1 Answers1

0

I think the easiest way is to set the value attribute of f:selectItems to a method which filters your original collection.

Otherwise you'd have to implement your own version of f:selectItems which allows filtering - as we once did in one of our projects.

dratewka
  • 2,104
  • 14
  • 15
  • I tried but it doesn't work like this: public List getProducts() throws SQLException { Iterator it = products.iterator(); while(it.hasNext()) { if(product.getCategory() != 1) products.remove(product); } return products; } – Mateusz Gaweł May 11 '13 at 17:23
  • So do you get an error? Nothing at all? What does exactly "doesn't work" mean in this case? – dratewka May 11 '13 at 17:42
  • One more thing - if you return a list of products instead of `SelectItem` objects you have to remember to set `f:selectItems` attributes like `itemValue` and `itemLabel`. If you forgot, that also may cause some problems. – dratewka May 11 '13 at 17:48