JSF Showcase
h:selectBooleanCheckbox
HtmlSelectBooleanCheckbox is a UISelectBoolean component that renders a checkbox.Immediate Usage
When the immediate attribute istrue
, the submitted value is converted and validated during APPLY_REQUEST_VALUES phase of the JSF lifecycle, rather than the normal PROCESS_VALIDATIONS phase.
Source Code
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> <!-- Example 1: ValueChangeListener execution when immediate is true --> <h:form> <h:outputLabel value="#{i18n['agree']}" /> <h:messages globalOnly="true" styleClass="feedback" /> <h:selectBooleanCheckbox id="checkbox" immediate="true" value="#{selectBooleanCheckboxModelBean.agree}" valueChangeListener="#{selectBooleanCheckboxBackingBean.valueChangeListener}"> </h:selectBooleanCheckbox> <hr /> <h:commandButton value="#{i18n['submit']}"> <f:ajax execute="@form" render="@form" /> </h:commandButton> <h:outputText id="modelValue" value="#{selectBooleanCheckboxModelBean.agree}" /> </h:form> <!-- Example 2: ValueChangeListener execution when immediate is false (the default) --> <h:form> <h:outputLabel value="#{i18n['agree']}" /> <h:messages globalOnly="true" styleClass="feedback" /> <h:selectBooleanCheckbox id="checkbox" value="#{selectBooleanCheckboxModelBean.agree}" valueChangeListener="#{selectBooleanCheckboxBackingBean.valueChangeListener}"> </h:selectBooleanCheckbox> <hr /> <h:commandButton value="#{i18n['submit']}"> <f:ajax execute="@form" render="@form" /> </h:commandButton> <h:outputText id="modelValue" value="#{selectBooleanCheckboxModelBean.agree}" /> </h:form> </ui:composition>
@ManagedBean @RequestScoped public class SelectBooleanCheckboxModelBean { private Boolean agree; public Boolean getAgree() { return agree; } public void setAgree(Boolean agree) { this.agree = agree; } }
@ManagedBean @RequestScoped public class SelectBooleanCheckboxBackingBean { private static final Logger logger = LoggerFactory.getLogger(SelectBooleanCheckboxBackingBean.class); @ManagedProperty(name = "selectBooleanCheckboxModelBean", value = "#{selectBooleanCheckboxModelBean}") private SelectBooleanCheckboxModelBean selectBooleanCheckboxModelBean; public void setSelectBooleanCheckboxModelBean(SelectBooleanCheckboxModelBean selectBooleanCheckboxModelBean) { this.selectBooleanCheckboxModelBean = selectBooleanCheckboxModelBean; } public void submit() { PhaseId phaseId = FacesContext.getCurrentInstance().getCurrentPhaseId(); logger.info("submit: phaseId=[{0}] agree=[{1}]", phaseId.toString(), selectBooleanCheckboxModelBean.getAgree()); } public void valueChangeListener(ValueChangeEvent valueChangeEvent) { FacesContext facesContext = FacesContext.getCurrentInstance(); PhaseId phaseId = facesContext.getCurrentPhaseId(); logger.debug("valueChangeListener: phaseId=[{0}]", phaseId.toString()); String phaseName = phaseId.toString(); FacesMessage facesMessage = new FacesMessage("The valueChangeListener method was called during the " + phaseName + " phase of the JSF lifecycle."); facesContext.addMessage(null, facesMessage); } }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20