user2504767
user2504767

Reputation:

Conditionally displaying JSF components in an if-else

I am using JSF 1.2 and I have the following output format:

<h:outputFormat value="#{txt.text_a}">
    <f:param value="#{bean.get_a}" />
</h:outputFormat>     

And I have also the following output text:

<h:outputText value="#{bean.get_b}" />

I would like to display them conditionally in an if-else case. In the backing bean, I have a boolean property visible for that. How can I implement it in an if-else case?

Upvotes: 0

Views: 1131

Answers (1)

LaurentG
LaurentG

Reputation: 11757

You could do it using two different blocks with the opposite rendered condition, as follows:

<h:outputFormat value="#{txt.text_a}" rendered="#{visible}">
  <f:param value="#{bean.get_a}" />
</h:outputFormat>  
<h:outputText value="#{bean.get_b}" rendered="#{not visible}" />

Where visible represents the condition for the text_a to be displayed.

Upvotes: 1

Related Questions