价值和项目价值之间的差异 [英] Difference between value and itemvalue

查看:85
本文介绍了价值和项目价值之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jsf中单选按钮的value和itemValue属性之间有什么区别?

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

推荐答案

该值用于发送在SelectItem对象中,而不是像itemValue这样的字符串。 itemValue是项值,它作为请求参数传递给服务器,但值是一个指向SelectItem实例的值绑定表达式。

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.

如果你看看这个JSF:

If you look at this JSF:

 <h:selectOneRadio value="">
    <f:selectItem itemValue="TestValue" itemLabel="TestLabel" />
</h:selectOneRadio>

转换为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>

因此value = valueBinding指向托管bean中的SelectItem,itemValue =正在存储的值提交。如果您决定添加一个值=#{TestBean.mySelectItem},它不会以任何方式更改输出的HTML,但JSF实现将知道应使用mySelectItem字段的getter属性。

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.

编辑:澄清更多答案。 SelectItem的value属性通过getter和setter属性将SelectItem绑定到托管bean中的SelectItem字段。如果您设置这样的值:

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>   

它将调用TestBean中的getMySelectItem()方法。正如你所看到的,这与itemValue没有任何关系,因为itemValue是用户提交表单时设置请求内容的值的重要工具。然后,itemValue将存储在h:selectOneRadio的值中,希望您可以像这样绑定一个String字段:

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>

现在,如果用户检查收音机对他来说如何: 1。radio one 值1将存储在名为selectedRadioValue的TestBean变量中。

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

这篇关于价值和项目价值之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆