The canonical JSF approach uses the rendered attribute for this. Here are some examples:
<h:someComponent rendered="#{bean.booleanValue}" /> <h:someComponent rendered="#{bean.intValue gt 10}" /> <h:someComponent rendered="#{bean.objectValue eq null}" /> <h:someComponent rendered="#{bean.stringValue ne 'someValue'}" /> <h:someComponent rendered="#{not empty bean.collectionValue}" /> <h:someComponent rendered="#{not bean.booleanValue and bean.intValue ne 0}" /> <h:someComponent rendered="#{bean.enumValue eq 'ONE' or bean.enumValue eq 'TWO'}" />
The difference with JSTL tags is that the rendered attribute is evaluated during rendering rendering, while JSTL tags are executed during build time. See Also JSTL in JSF2 Facelets ... makes sense?
So, if the variables needed to evaluate the condition have a narrower scope than the view scope (i.e. the query scope), then you should use the rendered attribute. For example, when re-rendering a group of components on an ajax request. Although JSTL tags may work equally well in this case, they can be evaluated too soon (that is, before the action is triggered, which in turn would change the conditions), and they will also violate the viewport. See Also @ViewScoped Breaks in Tag Handlers .
If the variables needed to evaluate the conditions have a wider scope, for example. system-wide or application-wide or hard-coded in some template clients, then JSTL tags are more efficient, as they will be evaluated only during the viewing time, and not every time when viewing the rendering. See Also How to mesh a composite JSF component?
source share