java value 和 itemvalue 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/325616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between value and itemvalue
提问by Warrior
What is the difference between the value and itemValue attribute of the radiobutton in Jsf?
Jsf中radiobutton的value和itemValue属性有什么区别?
采纳答案by Chris Dale
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.
该值旨在发送 SelectItem 对象,而不是像 itemValue 那样的 String。itemValue 是 items 值,它作为请求参数传递给服务器,但该值是指向 SelectItem 实例的值绑定表达式。
If you look at this JSF:
如果你看看这个 JSF:
<h:selectOneRadio value="">
<f:selectItem itemValue="TestValue" itemLabel="TestLabel" />
</h:selectOneRadio>
which turns into this HTML:
它变成了这个 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.
因此 value = valueBinding 指向托管 bean 中的 SelectItem,并且 itemValue = 正在提交的值。如果您决定添加一个 value="#{TestBean.mySelectItem}" 它不会以任何方式更改输出的 HTML,但 JSF 实现会知道应在此使用 mySelectItem 字段的 getter 属性。
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:
编辑:进一步澄清答案。SelectItem 的 value 属性通过 getter 和 setter 属性将 SelectItem 绑定到托管 bean 中的 SelectItem 字段。如果您像这样设置值:
<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:
它将调用 TestBean 中的 getMySelectItem() 方法。正如您所看到的,这与 itemValue 无关,因为 itemValue 负责设置用户提交表单时请求中的内容的值。然后 itemValue 将存储在 h:selectOneRadio 的值中,希望您已经绑定到这样的字符串字段:
<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
现在,如果用户检查他看起来像的无线电:“ 1. radio one”,则值“1”将存储在名为 selectedRadioValue 的 TestBean 变量中
回答by VonC
From this IBM article Adding row selection to a JSF datatable using radio buttons:
来自这篇 IBM 文章使用单选按钮将行选择添加到 JSF 数据表:
The attribute idis for the component value of the Radio Button Group. It will be bound to the Value field
该属性ID是单选按钮组的分量值。它将绑定到 Value 字段


The attribute selectedRowId is for the item valueof the radio button, and will be bound to the item value field
属性 selectedRowId 是为单选按钮的item 值,将绑定到 item value 字段



