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?
Asked
Active
Viewed 169 times
0
-
Can you post a concrete question as your question is pretty unclear? – skuntsel May 11 '13 at 16:39
-
Whats the problem of creating list? When not to create one is too much costly! – Sazzadur Rahaman May 11 '13 at 16:48
-
You can't only show some items inside a `f:selectItems`. You need to filter your list before. – Alexandre Lavoie May 11 '13 at 17:31
-
`itemDisabled` attribute of `f:selectItems` tag. See this answer http://stackoverflow.com/a/8257987/892994 i hope it will help. – erencan May 11 '13 at 19:52
1 Answers
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