What is the difference between the value and itemValue attribute of the radiobutton in Jsf?
2 Answers
The value is meant to send in a SelectItem object and not a String like itemValue is. The itemValue is the items value, which is passed to the server as a request parameter, but the value is a value binding expression that points to a SelectItem instance.
If you look at this JSF:
<h:selectOneRadio value="">
<f:selectItem itemValue="TestValue" itemLabel="TestLabel" />
</h:selectOneRadio>
which turns into this HTML:
<table>
<tr>
<td>
<input type="radio" name="j_id_id9" id="j_id_id9:0" value="TestValue" />
<label for="j_id_id9:0"> TestLabel</label>
</td>
</tr>
</table>
So value = valueBinding pointing to a SelectItem in your managed bean, and itemValue = the value that is being submitted. If you decided to add a value="#{TestBean.mySelectItem}" it would not change the outputted HTML in any way, but the JSF implementation would know that the getter property for the mySelectItem field should be used on this.
Edit: To clarify the answer a bit more. The value property of the SelectItem binds the SelectItem to an SelectItem field in the managed bean via getter and setter properties. If you set the value like this:
<h:selectOneRadio value="">
<f:selectItem itemValue="TestValue" itemLabel="TestLabel" value="#{TestBean.mySelect}"/>
</h:selectOneRadio>
it will invoke the getMySelectItem() method in the TestBean. As you can see this has nothing to do with the itemValue as the itemValue is resposible of setting the value of what goes in the request when the user submits the form. The itemValue will then be stored in the h:selectOneRadio's value which hopefully you have bound up to a String field like this:
<h:selectOneRadio value="#{TestBean.selectedRadioValue}">
<f:selectItem itemValue="1" itemLabel="1. radio one" />
<f:selectItem itemValue="2" itemLabel="2. radio two" />
</h:selectOneRadio>
Now if the user checks the radio which to him looks like: "1. radio one" the value "1" will be stored in the TestBean's variable called selectedRadioValue

- 2,222
- 2
- 26
- 39
-
1I think you've got a better (original) answer here, but I've read that first sentence 4 times, and still have trouble understanding it. Clarify? – jmanning2k Aug 25 '09 at 14:35
-
I agree with Jon (on the "better" answer part). +1 – VonC Aug 25 '09 at 15:23
-
Ive added more info now =) Hopefully this will clarify things – Chris Dale Aug 25 '09 at 15:53
From this IBM article Adding row selection to a JSF datatable using radio buttons:
The attribute id is for the component value of the Radio Button Group. It will be bound to the Value field
The attribute selectedRowId is for the item value of the radio button, and will be bound to the item value field

- 1,262,500
- 529
- 4,410
- 5,250
-
1Those images are copyright, and should not be used without permission. – jmanning2k Aug 25 '09 at 14:33