Creating the toggle button using SelectBooleanButton
The SelectBooleanButton component is used to select a yes or no decision with a toggle button:
<h:outputText value="Subscribe to Email Notifications: " />
<p:selectBooleanButton value="#{selectionController.subscribed}" onLabel="Yes" offLabel="No" onIcon="ui-icon-check" offIcon="ui-icon-close" />Here, the onLabel and offLabel attributes are mandatory. We can change the labels and icons using the onLabel, offLabel, onIcon, and offIcon attributes.
We can also add an event listener to the <p:selectBooleanButton> component using a nested <p:ajax> element.