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>
@Named
@RequestScoped
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) {
UIInput inputComponent = (UIInput) component;
Boolean value = (Boolean) inputComponent.getValue();
String summary = value ? "Checked" : "Unchecked";
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(summary));
}
}
}