简体   繁体   English

值与itemvalue之间的差异

[英]Difference between value and itemvalue

Jsf中radiobutton的value和itemValue属性有什么区别?

The value is meant to send in a SelectItem object and not a String like itemValue is. 该值用于发送SelectItem对象,而不是像itemValue那样的String。 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. 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. 因此value = valueBinding指向托管bean中的SelectItem,而itemValue =正在提交的值。 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. 如果您决定添加一个值=“#{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. SelectItem的value属性通过getter和setter属性将SelectItem绑定到托管bean中的SelectItem字段。 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. 它将调用TestBean中的getMySelectItem()方法。 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. 正如您所看到的,这与itemValue无关,因为itemValue可以设置用户提交表单时请求内容的值。 The itemValue will then be stored in the h:selectOneRadio's value which hopefully you have bound up to a String field like this: 然后itemValue将存储在h:selectOneRadio的值中,希望你绑定到String字段,如下所示:

<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变量中

From this IBM article Adding row selection to a JSF datatable using radio buttons : 从这篇IBM文章使用单选按钮向JSF数据表添加行选择

The attribute id is for the component value of the Radio Button Group. 属性id用于单选按钮组的组件值。 It will be bound to the Value field 它将绑定到Value字段

属性Id

The attribute selectedRowId is for the item value of the radio button, and will be bound to the item value field selectedRowId属性用于单选按钮的项值 ,并将绑定到项值字段

物品价值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM