SelectBooleanCheckbox is used to select a boolean value.
<div class="card">
<h:form>
<p:growl id="msg"/>
<h5 class="mt-0">Basic</h5>
<p:selectBooleanCheckbox value="#{selectBooleanView.value1}" itemLabel="Basic"/>
<h5>Remote</h5>
<p:selectBooleanCheckbox value="#{selectBooleanView.value2}" itemLabel="Ajax">
<p:ajax update="msg" listener="#{selectBooleanView.addMessage}"/>
</p:selectBooleanCheckbox>
</h:form>
</div>
package org.primefaces.showcase.view.input;
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIInput;
import jakarta.faces.context.FacesContext;
import jakarta.faces.event.AjaxBehaviorEvent;
import jakarta.inject.Named;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named
@RequestScoped
@RegisterForReflection(serialization = true)
public class SelectBooleanView {
private boolean value1;
private boolean value2;
private boolean value3;
public boolean isValue1() {
return value1;
}
public void setValue1(boolean value1) {
this.value1 = value1;
}
public boolean isValue2() {
return value2;
}
public void setValue2(boolean value2) {
this.value2 = value2;
}
public boolean isValue3() {
return value3;
}
public void setValue3(boolean value3) {
this.value3 = value3;
}
public void addMessage(AjaxBehaviorEvent event) {
UIComponent component = event.getComponent();
if (component instanceof UIInput inputComponent) {
Boolean value = (Boolean) inputComponent.getValue();
String summary = value ? "Checked" : "Unchecked";
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(summary));
}
}
}