Forums Register Login

problems with <h:selectOneMenu>

+Pie Number of slices to send: Send
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
No holds barred. And no bars holed. Except this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1499 times.
Similar Threads
Help - question on selectOneListbox and page reloads
selected value through select items
How to read the value selected in the selectOneMenu tag in the forwarded jsp page
SelectItem Pardox
SelectItem Help needed
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:35:49.