I have a list of categories and want to add one not existing category (an all category).
<h:selectOneMenu value="#{categoryBean.selectedCategory}"> <f:selectItems value="#{categoryBean.categorySelectItems}"/> <s:convertEntity /> </h:selectOneMenu>
private Shelf allCategory = new Category(1);
public List<SelectItem> getCategorySelectItems() { List<SelectItem> items = new ArrayList<SelectItem>(); items.add(new SelectItem(allCategory, "search All")); for (Category cat : getCategories()) { items.add(new SelectItem(cat, cat.getName())); } return items; }
For every item except the newly added allCategory
i get the right object, just when i select search All
i get a null instead of the object in setSelectedCategory(). And return items;
contains at the zero index the allCategory object like it should. And the POST is transmitting the 0 as index (like it would 2 or 3 for the other selectItems)