You were right - if you create your component as follows:
<p:selectBooleanCheckbox value="val" widgetVar="myCheckbox"/>
You can access this flag simply by accessing its widgetVar, in which case call the PrimeFaces client API to mark it as checked:
<script> myCheckbox.check(); </script>
Then you can bind the onchange event of your main flag to the javascript method, which checks or cancels the state of all flags "slave" depending on the state of the main field (prompting you to save the state in a hidden field).
Note that this can make your life easier to handle the ajax "change" event instead and implement the server side check / uncheck logic. Just make sure that you provide all the identifiers of all the sub flags in the update attribute of the p: ajax component:
<p:selectBooleanCheckbox id="masterChkBox" ...> <p:ajax event="change" listener="#{yourBean.handleMasterChange}" update="...all slavecheckbox ids..."/> </p:selectBooleanCheckbox>
source share