Difference between value and itemvalue

What is the difference between the value and itemValue attribute of the radiobutton in Jsf?


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" />

which turns into this HTML:

        <input type="radio" name="j_id_id9" id="j_id_id9:0" value="TestValue" />
        <label for="j_id_id9:0"> TestLabel</label>

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}"/>

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" />

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

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

Need Your Help

enable hibernate app to use clustered hazelcast

spring hibernate hazelcast

our prod environment architecture is decided to be like this:

asp.net is there a way to trigger Session_End like event when cookie expires?

asp.net session cookies

hope this is not a too basic of a question. I was wondering just like Session_end event is triggered when a session is expired, is there a way when using formsauthentication and a cookie expires th...