Difference between value and itemvalue

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

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


Need Your Help

Windows - preventing console window from closing if errors occured

windows shell batch-file

I'm writing a simple .bat script and I want it to open it by double click from Windows Explorer. If opened from Windows Explorer, console window automatically closes after script is finished.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.