JSF DataTable使用单选按钮选择一行 [英] JSF DataTable Select One Row Using Radio Button
问题描述
我正在使用JSF 1.1,我有一个ice:datatable,其中的行是从后备bean中获取的. 要选择要编辑的行,我需要为该行选择一个单选按钮. 当我使用单选按钮选择行时,出现以下错误.
I am using JSF 1.1 and I have a ice:datatable with rows getting fetched from backing bean. To select the row for editing I have a radio button for that row. When I select the row using the radio button I am getting the following error.
radio.name is undefined
在我的页面中,我按以下方式调用javascript
In my page I am calling the javascript as follows
<h:selectOneRadio styleClass="none" valueChangeListener="#{bean.setSelectedItem}"
onclick="dataTableSelectOneRadio(this);">
<f:selectItem itemValue="null" />
</h:selectOneRadio>
任何我的javascript函数
Any my javascript function
function dataTableSelectOneRadio(radio) {
var id = radio.name.substring(radio.name.lastIndexOf(':'));
var el = radio.form.elements;
for (var i = 0; i < el.length; i++) {
if (el[i].name.substring(el[i].name.lastIndexOf(':')) == id) {
el[i].checked = false;
}
}
radio.checked = true;
}
如何解决此错误?
谢谢
推荐答案
显然,IceFaces不会为单选按钮生成name
属性,也不会在生成的<input type="radio">
元素上放置onclick
.尝试改用id
.用radio.id
替换JavaScript代码中的radio.name
.如果徒劳,则需要检查生成的HTML输出(在浏览器中打开页面,右键单击并查看源代码),并相应地更改JS代码.
Apparently IceFaces doesn't generate name
attribute for the radio button or doesn't put onclick
on the generated <input type="radio">
element. Try using id
instead. Replace radio.name
in JavaScript code by radio.id
. If in vain, you need to check the generated HTML output (open page in browser, rightclick and View Source) and alter the JS code accordingly.
这篇关于JSF DataTable使用单选按钮选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!