h:selectBooleanCheckbox

HtmlSelectBooleanCheckbox is a UISelectBoolean component that renders a checkbox.

Immediate Usage

When the immediate attribute is true, 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

  1. <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
  2. xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
  3.  
  4. <!-- Example 1: ValueChangeListener execution when immediate is true -->
  5. <h:form>
  6. <h:outputLabel value="#{i18n['agree']}" />
  7. <h:messages globalOnly="true" styleClass="feedback" />
  8. <h:selectBooleanCheckbox id="checkbox" immediate="true" value="#{selectBooleanCheckboxModelBean.agree}"
  9. valueChangeListener="#{selectBooleanCheckboxBackingBean.valueChangeListener}">
  10. </h:selectBooleanCheckbox>
  11. <hr />
  12. <h:commandButton value="#{i18n['submit']}">
  13. <f:ajax execute="@form" render="@form" />
  14. </h:commandButton>
  15. <h:outputText id="modelValue" value="#{selectBooleanCheckboxModelBean.agree}" />
  16. </h:form>
  17.  
  18. <!-- Example 2: ValueChangeListener execution when immediate is false (the default) -->
  19. <h:form>
  20. <h:outputLabel value="#{i18n['agree']}" />
  21. <h:messages globalOnly="true" styleClass="feedback" />
  22. <h:selectBooleanCheckbox id="checkbox" value="#{selectBooleanCheckboxModelBean.agree}"
  23. valueChangeListener="#{selectBooleanCheckboxBackingBean.valueChangeListener}">
  24. </h:selectBooleanCheckbox>
  25. <hr />
  26. <h:commandButton value="#{i18n['submit']}">
  27. <f:ajax execute="@form" render="@form" />
  28. </h:commandButton>
  29. <h:outputText id="modelValue" value="#{selectBooleanCheckboxModelBean.agree}" />
  30. </h:form>
  31.  
  32. </ui:composition>
  1. @ManagedBean
  2. @RequestScoped
  3. public class SelectBooleanCheckboxModelBean {
  4.  
  5. private Boolean agree;
  6.  
  7. public Boolean getAgree() {
  8. return agree;
  9. }
  10.  
  11. public void setAgree(Boolean agree) {
  12. this.agree = agree;
  13. }
  14. }
  1. @ManagedBean
  2. @RequestScoped
  3. public class SelectBooleanCheckboxBackingBean {
  4.  
  5. private static final Logger logger = LoggerFactory.getLogger(SelectBooleanCheckboxBackingBean.class);
  6.  
  7. @ManagedProperty(name = "selectBooleanCheckboxModelBean", value = "#{selectBooleanCheckboxModelBean}")
  8. private SelectBooleanCheckboxModelBean selectBooleanCheckboxModelBean;
  9.  
  10. public void setSelectBooleanCheckboxModelBean(SelectBooleanCheckboxModelBean selectBooleanCheckboxModelBean) {
  11. this.selectBooleanCheckboxModelBean = selectBooleanCheckboxModelBean;
  12. }
  13.  
  14. public void submit() {
  15. PhaseId phaseId = FacesContext.getCurrentInstance().getCurrentPhaseId();
  16. logger.info("submit: phaseId=[{0}] agree=[{1}]", phaseId.toString(), selectBooleanCheckboxModelBean.getAgree());
  17. }
  18.  
  19. public void valueChangeListener(ValueChangeEvent valueChangeEvent) {
  20.  
  21. FacesContext facesContext = FacesContext.getCurrentInstance();
  22. PhaseId phaseId = facesContext.getCurrentPhaseId();
  23. logger.debug("valueChangeListener: phaseId=[{0}]", phaseId.toString());
  24.  
  25. String phaseName = phaseId.toString();
  26. FacesMessage facesMessage = new FacesMessage("The valueChangeListener method was called during the " +
  27. phaseName + " phase of the JSF lifecycle.");
  28. facesContext.addMessage(null, facesMessage);
  29. }
  30. }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20