简体   繁体   English

JSF / RichFaces:条件文本样式

[英]JSF/RichFaces: conditional text styling

I have a string which can be yes or no, instantiated in an object in a Java backing bean. 我有一个可以是yes或no的字符串,在Java辅助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. 我似乎无法找到有条件地将文本设置为红色或绿色的最佳方式,这取决于JSF是否分别从bean获得yes或no。 I'm using richfaces, but should I be using <c:if> tags? 我正在使用richfaces,但我应该使用<c:if>标签吗?

(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'} ) 制作两个具有不同样式的<h:outputText>组件,每个组件具有不同的rendered属性(一个#{yourVar == 'yes'} ,另一个#{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)}" 定义一个(jstl / facelets / jsf 2.0)函数,它将var作为参数并返回一个样式/类 - styleClass="#{my:getStyleClass(yourVar)}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM