0

I have 4 checkbox. I want to do pairing selection (select 1 checkbox then auto select another checkbox). checkbox1 will pair with checkbox4. checkbox2 will pair with checkbox3.

xhtml (will display 4 checkbox):

    <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
    }
  • 1
    You'll get little help if you don't show your code and tell what you've tried. – Ignatius Apr 08 '19 at 03:11
  • Possible duplicate of [Check/Uncheck checkbox with JavaScript?](https://stackoverflow.com/questions/8206565/check-uncheck-checkbox-with-javascript) – Selaron Apr 08 '19 at 06:23
  • @selaron: I think using server-side ajax is another solution... – Kukeltje Apr 08 '19 at 13:54
  • I have edit my question and put in my code. Kindly help me how to check 2 checkbox as per condition above. I am new in jsf. – Ruzaimah Samat Apr 11 '19 at 01:51
  • @Kukeltje that's true - there is now an answer covering this on OPs' 2nd attempt: [How to check another checkbox when click first checkbox? My checkbox list retrieve from datafile](https://stackoverflow.com/questions/55643370/how-to-check-another-checkbox-when-click-first-checkbox-my-checkbox-list-retrie) – Selaron Apr 12 '19 at 06:28

0 Answers0