Hi,
I think I must be missing something - I've been using JSF for about 10 days now and have built a basic application.
The problem I'm having is with the <h:selectOneMenu> or HtmlSelectOneMenu elements. Unlike all of the examples I've found I need to populate the combo box dynamically, from a database (using Hibernate). Each menu item represented by a bean (called a NamedDimensionBean) that contains a getId(), getName() and getString() method.
So what I did was to create a list of SelectItem with the label get to the result of calling getName() on each of my beans and the value set to the bean itself. Just for good measure I wrap all the SelectItem's in a SelectItems object.
I then put that in an EL expression inside the <h:selectOneMenu> like this:
<h:selectOneMenu id="statusInput"
value="#{addUserBean.userStatusString}">
<f:selectItems value="#{addUserBean.statuses}"/>
</h:selectOneMenu>
The part I don't understand is: what is the point of having the 'value' field in the SelectItem if the 'value' of the <h:selectOneMenu> has to refer to a string? Why doesn't it bind to a type of the underlying value?
The SelectItem docs seem to suggest that it's value field is passed to the 'model' when it's selected, but how?
In the meantime, I'm working around it by converting the selected string back into the object I want, but it's pretty unsightly. Can anyone help?
Thanks in advance,
Jim
I think I must be missing something - I've been using JSF for about 10 days now and have built a basic application.
The problem I'm having is with the <h:selectOneMenu> or HtmlSelectOneMenu elements. Unlike all of the examples I've found I need to populate the combo box dynamically, from a database (using Hibernate). Each menu item represented by a bean (called a NamedDimensionBean) that contains a getId(), getName() and getString() method.
So what I did was to create a list of SelectItem with the label get to the result of calling getName() on each of my beans and the value set to the bean itself. Just for good measure I wrap all the SelectItem's in a SelectItems object.
I then put that in an EL expression inside the <h:selectOneMenu> like this:
<h:selectOneMenu id="statusInput"
value="#{addUserBean.userStatusString}">
<f:selectItems value="#{addUserBean.statuses}"/>
</h:selectOneMenu>
The part I don't understand is: what is the point of having the 'value' field in the SelectItem if the 'value' of the <h:selectOneMenu> has to refer to a string? Why doesn't it bind to a type of the underlying value?
The SelectItem docs seem to suggest that it's value field is passed to the 'model' when it's selected, but how?
In the meantime, I'm working around it by converting the selected string back into the object I want, but it's pretty unsightly. Can anyone help?
Thanks in advance,
Jim