I`m using JSF and I have an output text per example "qwerty" that I want to display / format differently if some conditions will be met. So per example if:
and so on.
Is there a way?
You can use a ternary operator in order to choose the style you want to apply depending on the condition:
<h:outputText value="qwerty"
style="#{backingBean.cond1 ? 'text-decoration:line-through;':'fontstyle:italic;'}">
And it would be even better if you use css classes in order of inline styles. Good luck!
Using the 'condition' inline in the EL is also possible, see using greater than logical expression in rendered attribute. Read also the discussion about using inline in the xhtml or in the javabean
Neat way is to create CSS classes
<h:outputText value="qwerty"
styleClass="#{backingBean.cond1 ? 'classA' : 'classB'}" />
In similar situations, I use following
<h:outputText value="yourValueFromYourBeanOrWhatever" styleClass="anArbitraryName#{managedBean.condition}"/>
And in my CSS file I define the classes:
.anArbitraryNametrue{}
and
.anArbitraryNamefalse{}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With