I have a Collection of model objects in my backing bean, and I want to use the f:selectItems tag to display them in a h:selectOneMenu
. I have read many tutorials that recommend using a collection of SelectItem objects instead of my model POJOs. However, I do not want to do this because it ties your model to a faces presentation. Is there any way to achieve this? I keep getting a Servlet Exception - "incompatible with javax.faces.model.SelectItem."
I have posted a few sample snippets below:
Java:
@Component(value = "headerBean")
@Scope(value = "session")
class HeaderBean{
private Collection<ValueObject> myCollectionOfValueObjects = new ArrayList<ValueObject>();
// ...
// getter, setters, whatnot...
// ...
}
JSP:
<h:selectOneMenu id="selectMenu" value="#{headerBean.myValueObject}">
<f:selectItems value="#{headerBean.myCollectionOfValueObjects}"/>
</h:selectOneMenu>