Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF/RichFaces: conditional text styling

I have a string which can be yes or no, instantiated in an object in a Java backing bean. I can't seem to find the best way to conditionally style the text red or green dependent on whether the JSF gets yes or no from the bean respectively. I'm using richfaces, but should I be using <c:if> tags?

like image 587
volvox Avatar asked Feb 08 '10 17:02

volvox


1 Answers

(in order of preference):

  • style="color: #{yourVar == 'yes' ? 'green' : 'red'};"
  • make two <h:outputText> components with different styles, each with a different rendered attribute (one #{yourVar == 'yes'} and the other #{yourVar == 'no'})
  • define a (jstl/facelets/jsf 2.0) function that takes the var as argument and returns a style/class - styleClass="#{my:getStyleClass(yourVar)}"
like image 157
Bozho Avatar answered Oct 03 '22 04:10

Bozho