首页 > 解决方案 > 我有 4 个复选框,c1、c2、c3 和 c4。如果选择了 c1,那么 c4 将被自动选择。我如何在 jsf 中实现这一点?

问题描述

我有 4 个复选框。我想做配对选择(选择 1 个复选框,然后自动选择另一个复选框)。checkbox1 将与 checkbox4 配对。checkbox2 将与 checkbox3 配对。

xhtml(将显示 4 个复选框):

    <p:dataTable id="popup1" var="comp1" rows="10"
    value="#{ExaBackingBean.managedBean.popupcomp1List}"
    editable="true"
    selection="#{ExaBackingBean.managedBean.popupcomp1Select}"
    emptyMessage="#{lbl['lbl.datatable.msg.no.records.found']}"
    rowKey="#{comp1.documentId}" rowIndexVar="index">
    <ac:paginator for="popup1"></ac:paginator>

    <p:column style="width:3px;text-align:center;" >
    <p:selectBooleanCheckbox value="#{comp1.selected}">
        <p:ajax listener="#{ExaBackingBean.ckechboxSelectPairingAction(comp1.documentId)}" partialSubmit="true" process="@this" update="@([id$=CompChecklist])" />
    </p:selectBooleanCheckbox>
</p:column>

public void ckechboxSelectPairingAction(int documentId) throws Exception {
    System.out.println("documentId xxxxxxxxxxxx"+documentId);
    if (documentId == 1) { 
        // ---> checkbox1 & checkbox4 should be selected, how to check the checkbox1 & 4?
    } else if(documentId == 2) { 
            System.out.println("documentId kat dalam"+documentId);
                // ---> checkbox2 & checkbox3 should be selected
    }

标签: jsf

解决方案


推荐阅读