c:choose

The JSF runtime includes c:choose implementation of the JSTL <c:choose> JSP tag. If JSTL sounds familiar (heavily used in JSP) then, it provides the same features for JSF too.

General Usage

Use together with c:when and c:otherwise to choose which portion of code will be rendered depending in a condition that can be set in test attribute from c:when tag handler.
Disabled

Source Code

  1. <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
  2. xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
  3.  
  4. <c:choose>
  5. <c:when test="#{jSTLBackingBean.rendered}">
  6. Enabled
  7. </c:when>
  8. <c:otherwise>
  9. Disabled
  10. </c:otherwise>
  11. </c:choose>
  12.  
  13. </ui:composition>
  1. @ManagedBean
  2. @RequestScoped
  3. public class JSTLBackingBean {
  4.  
  5. private boolean rendered;
  6.  
  7. public boolean isRendered() {
  8. return rendered;
  9. }
  10.  
  11. public void setRendered(boolean rendered) {
  12. this.rendered = rendered;
  13. }
  14.  
  15. public void toggleRendered(ActionEvent event) {
  16. this.rendered = !rendered;
  17. }
  18.  
  19. }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20