0
votes

I have 2 items:
radiobuttons
outputtext

What I'm trying to do is: When the user checks a radiobutton -> get the itemLabel of the checked radiobutton in my outputtext. (not itemValue)

I have following code which shows the itemValue in the output text:

<h:form>
<p:selectOneRadio layout="pageDirection" id="test" name="testy" value="#{myBean.testValue}">
<p:ajax update="testOutput"/>
<p:selectItems value="#{myBean.getAllTestItems()}" var="selecter" itemLabel="#{selecter.label}" itemValue="#{selecter.val}"/>
</p:selectOneRadio>

<h:outputText id="testOutput" value="#{myBean.testValue}"/>
</h:form>

When i select one of the radiobuttons, I get the itemValue in the outputText. However I would like to get the itemLabel of the selected item in the outputText.

How do I get the label instead of the value of the radiobutton?

1

1 Answers

1
votes

Several ways.

  1. Get it based on the collection behind #{myBean.getAllTestItems()} which already contains the items with both the label and the value. Find the item matching the selected value in there and then get the label.

  2. Submit #{selecter} instead of #{selecter.val} as radio button item value. This way you can display the label by #{myBean.testValue.label}. You only need to provide a Converter to convert between String (in HTML and HTTP request parameter) and Selecter (in Java model).

See also: