为什么h:selectOneRadio没有一个“名称"?属性? [英] Why does h:selectOneRadio does not have a "name" attribute?

查看:129
本文介绍了为什么h:selectOneRadio没有一个“名称"?属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对SelectOneRadio进行一些疯狂的分组,因此我决定创建自己的自定义组件,该组件允许我指定<input>标记的name属性(如您所知,相同的name表示无线电按钮在同一组中).渲染器是正确的,所以我有一个<input>曾经用来渲染这样的

I want to do some crazy grouping with SelectOneRadio, so I decide to create my own custom component that allow me to specify the name attribute of the <input> tag (as you know, same name means the radio buttons are in the same group). The renderer is correct, so I have a <input> that used to render like this

<input name="myForm:test1" id="myForm:test1:0" value="0" type="radio">

现在这样渲染

<input name="foo" id="myForm:test1:0" value="0" type="radio">

但是,当我提交表单时,EL停止工作(与h:commandButton和p:commandButton相同).所以如果我有这个

However, EL stop working when I submit a form (same for h:commandButton and p:commandButton). So if I have this

<xxx:selectOneRadio id="test1" value="#{myBean.selectedFood}">

然后进行EL工作,selectedFood打印出校正后的值,但是如果我输入

then EL work, selectedFood print out the corrected value, but if I put in

<xxx:selectOneRadio id="test1" value="#{myBean.selectedFood}" groupId="foo"> 

,这将在<input>标记中生成name=foo.然后,EL装订停止工作. selectedFoodnull.

which will make the name=foo in the <input> tag. Then EL binding stop working. selectedFood is null.

更有趣的是,如果我输入

More interestingly, If I put in this

<xxx:selectOneRadio id="test1" value="#{myBean.selectedFood}" groupId="myForm:test1">

哪个myForm:test1是正确的客户端ID,然后EL绑定再次起作用,因此看起来不是使绑定停止起作用的是我的代码. JSF是否需要input标记的name属性作为客户端ID?

which myForm:test1 is the correct client Id, then EL binding work again, so it does not look like it is my code that make the binding stop working. Does JSF require the name attribute of the input tag to the client id?

推荐答案

name成为HTTP请求参数名称,必须使用它来收集提交的HTTP请求参数值.这默认为JSF组件客户端ID,并且收集是在Rendererdecode()方法(或UIComponent本身)中进行的.您还需要覆盖/实现Rendererdecode(),以更改获取请求参数值的方式.

The name becomes the HTTP request parameter name and this has to be used to collect submitted HTTP request parameter values. This defaults to the JSF component client ID and the collecting happens in the decode() method of the Renderer (or the UIComponent itself). You need to override/implement the decode() of the Renderer as well to change the way how you get request parameter values.

这篇关于为什么h:selectOneRadio没有一个“名称"?属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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