JSF/RichFaces: conditional text styling

后端 未结 1 1990
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-07 15:44

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 depend

1条回答
  •  北荒
    北荒 (楼主)
    2021-02-07 16:17

    (in order of preference):

    • style="color: #{yourVar == 'yes' ? 'green' : 'red'};"
    • make two 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 讨论(0)
提交回复
热议问题