0

I'm dealing with a wizard in primefaces like this one:

http://www.primefaces.org/showcase/ui/wizard.jsf

I would like to get the raw text from a selectOneMenu (from one of the tabs) and show it in the confirmation tab.

My selectOneMenu looks like this:

<p:selectOneMenu id="vinculos"
      value="#{socioAdicional.idVinculo}" required="true"
      label="Vinculo">
            <f:selectItem itemLabel="#{mensajes.combos_empty_txt}" itemValue="#{null}" />
            <f:selectItems value="#{controladorCombos.vinculos}"
                  var="vinculo" itemLabel="#{vinculo.descripcion}"
                  itemValue="#{vinculo.id}" />
</p:selectOneMenu>

All the values are obtained from a webservice and can't be stored in an map attribute, cause we are using other buffering strategies...

I've tried so far to print that text (on a different tab) like this:

<b>Vinculo: </b><h:outputText value="#{p:component('vinculos').getSelectedValue()}"/>

Any ideas?

Thanks!

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
Sebastián
  • 1
  • 2
  • 2
  • 4

1 Answers1

2

Either use a Map<ItemId, Item> as available items, so that you can get the whole Item at hands based on the selected item ID:

private Long selectedItemId;
private Map<Long, Item> availableItems;
<h:selectOneMenu value="#{bean.selectedItemId}">
    <f:selectItems value="#{bean.availableItems.values()}" var="item"
        itemValue="#{item.id}" itemLabel="#{item.description}" />
</h:selectOneMenu>
...
<b>Selected item:</b> #{bean.availableItems[bean.selectedItemId].description}.

Or use whole Item instead of Id as selected item, with a converter, so that you immediately already have the whole Item at hands:

private Item selectedItem;
private List<Item> availableItems;
<h:selectOneMenu value="#{bean.selectedItem}" converter="itemConverter">
    <f:selectItems value="#{bean.availableItems}" var="item"
        itemValue="#{item}" itemLabel="#{item.description}" />
</h:selectOneMenu>
...
<b>Selected item:</b> #{bean.selectedItem.description}.
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for the answer! I can't hold all available items on a map, since there are lots and lots of selectOneMenu widgets and all values are obtained from a webservice (those values may change between two requests) – Sebastián May 17 '13 at 17:40
  • 1
    To save yourself from converter pain, you may find OmniFaces `SelectItemsConverter` helpful. http://showcase.omnifaces.org/converters/SelectItemsConverter – BalusC May 17 '13 at 19:15
  • Refer post, http://stackoverflow.com/questions/3141716/jsf-selectitems-how-to-get-both-label-and-value/23167788#23167788, using, List : may help! – AVA Apr 19 '14 at 09:13