选中Richfaces Treenode的所有框 [英] Check All box for Richfaces Treenode

查看:52
本文介绍了选中Richfaces Treenode的所有框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试创建一个复选框以检查treenode中的所有项目.我是JSF的新手,所以我很困惑如何在树上而不是表上实现它.这是当前代码:

Trying to create a checkbox to check all items in a treenode. I'm kind of new to JSF so I'm pretty stumped as how to implement this on a tree instead of a table. This is the current code:

<rich:panel style="width:400px;">           
            <h:selectBooleanCheckbox id="vehicleAll" onclick="selectAllModel(this.checked);">
            </h:selectBooleanCheckbox>
            <h:outputText value="  ALL"/>
        <rich:tree id="vehicleTree" switchType="client" 
            value="#{applicationScope.demoModelGrpList}" var="node" ajaxKeys="#{null}"
            binding="#{demoRptController.vehicleUiTree}"
            nodeSelectListener="#{demoRptController.selectionListener}"
            changeExpandListener="#{demoRptController.expansionListener}"
            ajaxSubmitSelection="true">
            <rich:treeNode id="modelNode" ajaxSingle="true" 
                icon="/images/pixel_node.gif" iconLeaf="/images/pixel_node.gif">
                <h:selectBooleanCheckbox id="cbxNode" value="#{node.selected}" style="position:relative; float:left; left:-22px;" class="vcBx">
                </h:selectBooleanCheckbox>
                <h:outputText value="#{node.name}" style="position:relative; float:left; left:-16px;"/>
            </rich:treeNode>
        </rich:tree>
    </rich:panel>

脚本为:

<script type="text/javascript">
<![CDATA[
function selectAllModel(checks) {
    alert("calling select all");
    var array = document.getElementsByTagName("input");
    for(var i = 0; i < array.length; i++)
    {
       if(array[i].type == "checkbox")
       {
          if(array[i].className == "vcBx")
           {
            array[i].checked = checks;
           }
       }
    }
}
    ]]>
</script>

我将警报放置在此处以进行测试;它甚至没有被调用.我很确定自己的语法正确,所以这让我挠头.

I placed the alert there for testing purposes; it's not even being called. I'm pretty sure I have my syntax correct so this has me scratching my head.

推荐答案

回答我自己的问题,以使遇到相同问题的任何人受益.

Answering my own question for the benefit of anyone having the same problem.

显然,我不能使用select作为函数名.那解决了一个问题;我只需要重命名该函数,现在就可以调用它了.

Apparently I can't use select for a function name. That solves one problem; I simply had to rename the function and now it's being called.

要解决其他问题(未选中复选框),我必须查找treenode生成的特定ID.看到与该节点的索引有关的仅一位数字发生变化,我设置了下面指​​定的循环以逐个选择复选框,并根据ALL复选框的状态对其进行更改.有点令人费解,但这是我发现满足需要完成的工作的最佳方式.从我的实验中,按输入或类型选择复选框似乎不适用于抓取h:selectBooleanCheckbox.如果我做错了,请随时纠正我.

To solve the other (checkboxes not being selected), I had to look up the specific ids being generated by the treenode. Seeing that only one digit changes pertaining to the index of the node, I setup the loop specified below to select the checkboxes one by one and change them according to the status of the ALL checkbox. A bit convoluted, but it's the best way I've found to satisfy what needed to be done. From my experiments, selecting by input or type checkbox doesn't seem to work with grabbing h:selectBooleanCheckbox. Please feel free to correct me if I'm wrong on this.

或者,您可以使用indexOf并使用该节点的ID,但是我只需要选择父节点,而无需选择任何子节点,因为这样做还选择了所有子节点.

Alternatively, you can use indexOf using the id for the node, but I only needed the parent nodes selected and none of the children, as doing this also selected all the child nodes.

function ccAllModel(checks) {
    for (var i = 0; i < 9; i++) {
        var vehicleId = "demoRptForm:vehicleTree:" + i + "::cbxNode";
        var array = document.getElementById(vehicleId);
        array.checked = checks.checked;
    }
}

这篇关于选中Richfaces Treenode的所有框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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