Make use of the rendered
attribute. It takes a boolean expression.
<h:inputText value="#{bean.input}" rendered="#{bean.editmode}" />
<h:outputText value="#{bean.input}" rendered="#{!bean.editmode}" />
If the expression evaluates true
, the component will be rendered in the component tree and be visible in the generated HTML output. If it evaluates false
, it will not be rendered and thus not be emitted to the HTML output.
Here are several other examples how you could express a boolean expression.
<h:someComponent rendered="#{bean.booleanValue}" />
<h:someComponent rendered="#{bean.intValue > 10}" />
<h:someComponent rendered="#{bean.objectValue == null}" />
<h:someComponent rendered="#{bean.stringValue != 'someValue'}" />
<h:someComponent rendered="#{!empty bean.collectionValue}" />
<h:someComponent rendered="#{!bean.booleanValue && bean.intValue != 0}" />
<h:someComponent rendered="#{bean.stringValue == 'oneValue' || bean.stringValue == 'anotherValue'}" />