如何在h:datatable jsf2.0中对单选按钮进行分组 [英] How to group Radio Buttons in h:datatable jsf2.0

查看:98
本文介绍了如何在h:datatable jsf2.0中对单选按钮进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JSF2的h:datatable中有一列单选按钮,但是我找不到将它们分组的方法.意味着可以同时选择所有这些对象,因为单选按钮的整个点都是这样,因此在任何给定时间只能选择一个.我相信会有标准的做法.

I have a column of radio buttons in h:datatable in JSF2 but I can not find a way to group them. Meaning all of them can be selected at the same time where as whole point of radio button is so that only one can be selected at any given time. I am sure there will be standard way of doing it.

我正在使用myfaces.如果确实需要,可以使用richfaces.

I am using myfaces. Can use richfaces if really needed to.

任何人都可以帮忙吗

推荐答案

<h:dataTable>中使用标准JSF <h:selectOneRadio>组件时,您需要在游戏中添加JavaScript镜头,以取消选中其中的所有其他单选按钮.选中同一列.

When using standard JSF <h:selectOneRadio> component inside a <h:dataTable> you'll need to bring a shot of JavaScript into the game which unchecks all other radio buttons in the same column when one is checked.

<h:column>
    <h:selectOneRadio onclick="uncheckOthers(this);">
</h:column>

使用

function uncheckOthers(radio) {
    var name = radio.name.substring(radio.name.lastIndexOf(':'));
    var elements = radio.form.elements;
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].name.substring(elements[i].name.lastIndexOf(':')) == name) {
            elements[i].checked = false;
        }
    }
    radio.checked = true;
}

这篇关于如何在h:datatable jsf2.0中对单选按钮进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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