tags:

views:

21

answers:

1

I have thought about this for a while - not getting a good idea.

This is the problem. I will have to display a text either in a text box or as an output text. How do I do this using a boolean variable in JSF?

I do not want to make an h:inputText and disable/make read only, it based on the boolean , I want to display a clean label or an output text.

suggestions ?

+3  A: 

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'}" />
BalusC
+1 Simple and Elegant. I'll have to train my mind to think better.hmmm...Thanks BalusC.
gurupriyan.e
You're welcome.
BalusC