h:selectBooleanCheckbox

HtmlSelectBooleanCheckbox is a UISelectBoolean component that renders a checkbox.

General Usage

The value of the component must be of type boolean or Boolean.
I agree to the terms of the license agreement

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">

	<h:form>
		<f:facet name="label">
			<h:selectBooleanCheckbox id="checkbox"
				required="#{showcaseModelBean.selectedComponent.required}"
				value="#{selectBooleanCheckboxModelBean.agree}" />
			#{i18n['agree']}
		</f:facet>
		<h:outputText styleClass="pad-left" value="#{i18n['i-agree-to-the-terms-of-the-license-agreement']}" />
		<br />
		<h:message for="checkbox" />
		<hr />
		<h:commandButton action="#{selectBooleanCheckboxBackingBean.submit}" 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