开发者

JSF/RichFaces: conditional text styling

开发者 https://www.devze.com 2022-12-19 18:40 出处:网络
I have a string which can be yes or no, instantiated in an object in a Java ba开发者_运维知识库cking bean.I can\'t seem to find the best way to conditionally style the text red or green dependent on w

I have a string which can be yes or no, instantiated in an object in a Java ba开发者_运维知识库cking 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?


(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)}"
0

精彩评论

暂无评论...
验证码 换一张
取 消