Skip to Content
JavaServer Faces
book

JavaServer Faces

by Hans Bergsten
April 2004
Intermediate to advanced
606 pages
20h 4m
English
O'Reilly Media, Inc.
Content preview from JavaServer Faces

Conditionally Render Components

So far, the components we’ve created are always shown to the user, but sometimes that’s not what we want. The menu area in the sample application, for instance, contains buttons for accepting or rejecting a report only if the current user is a manager. Component properties may also depend on runtime conditions, e.g., the way the menu area buttons are enabled or disabled depending on the current report’s status in the sample application.

Figure 6-6 shows the menu area as it appears to a regular user for a brand new report without entries, i.e., without the buttons available only to managers and with all buttons disabled.

Menu area
Figure 6-6. Menu area

If you come from a JSP background and have used JSTL a bit, your first impulse is likely to use the JSTL <c:if> or <c:choose> actions for conditional processing along these lines:

<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <f:view> <h:form> <table cellpadding="0" cellspacing="0" width="100%"> <tr> <td> <h:commandButton value="New" disabled="#{reportHandler.currReport.status == 0}" /> <h:commandButton value="Delete" disabled="#{reportHandler.currReport.status == 0 || reportHandler.currReport.status == 2 || reportHandler.currReport.status == ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Core JavaServer™ Faces

Core JavaServer™ Faces

David Geary, Cay S. Horstmann
Core JavaServer Faces, Second Edition

Core JavaServer Faces, Second Edition

David Geary, Cay Horstmann

Publisher Resources

ISBN: 0596005393Supplemental ContentErrata Page