tags:

views:

21

answers:

1

I want to get value and label of the selected items of a h:selectManyListbox.

I've this:

<h:selectManyListbox id="myList" size="10" value="#{search.selectedItems}">
    <f:selectItems id="myListID" value="#{search.itemsList}">
</h:selectManyListbox>

The problem is that when I submit the form I get only the a List<String> value and I need both: values and labels selected.

How can I get this?

A: 

You can't. HTML won't send the option label to the server side. Besides, you normally already know the label associated with the value in the server side. Just have some mapping of label-value pairs (e.g. Map<String, String>) so that you can obtain the associated label by the selected value (even more, you can reuse the map in <f:selectItems>).

That said, the need to know the label is a design smell. Shouldn't this information go in the value in first place (as well)?

BalusC
yeah that would be an option, but i've names of clients with extrange characters like ', ", /, \, etc... and have repeated names to, so i can't use this like a value. thanks for the answer i'll try the map<String, String> thing
ErVeY