JSF outputtext 条件显示/样式.视情况而定 [英] JSF outputtext conditional display/styling. Differently depending on condition

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

问题描述

我正在使用 JSF,并且每个示例qwerty"都有一个输出文本,如果满足某些条件,我想以不同的方式显示/格式化.所以每个例子如果:

I`m using JSF and I have an output text per example "qwerty" that I want to display / format differently if some conditions will be met. So per example if:

  • cond1 为真,那么我想显示 qwerty
  • cond1 为假,然后我想显示 qwerty

等等.

有办法吗?

推荐答案

您可以使用 三元运算符根据条件选择要应用的样式:

You can use a ternary operator in order to choose the style you want to apply depending on the condition:

<h:outputText value="qwerty" 
    style="#{backingBean.cond1 ? 'text-decoration:line-through;':'fontstyle:italic;'}">

如果您按照内联样式的顺序使用 css 类会更好.祝你好运!

And it would be even better if you use css classes in order of inline styles. Good luck!

在 EL 中使用条件"内联也是可能的,请参阅 在渲染属性中使用大于逻辑表达式.另请阅读 关于使用的讨论在 xhtml 或 javabean 中内联

Using the 'condition' inline in the EL is also possible, see using greater than logical expression in rendered attribute. Read also the discussion about using inline in the xhtml or in the javabean

这篇关于JSF outputtext 条件显示/样式.视情况而定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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