JSF/RichFaces:条件文本样式 [英] JSF/RichFaces: conditional text styling

查看:139
本文介绍了JSF/RichFaces:条件文本样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以是或否的字符串,该字符串在Java支持bean的一个对象中实例化.我似乎找不到最佳的方法来有条件地将文本设置为红色或绿色,这取决于JSF分别从bean获得是还是否.我正在使用richfaces,但是我应该使用<c:if>标记吗?

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?

推荐答案

(按优先顺序排列):

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

这篇关于JSF/RichFaces:条件文本样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆