我有一个简单的组件——CommandButton
<tr:commandButton text="test" styleClass="form-button"
actionBean="#{testPage}" action="synchAction"
partialSubmit="true" id="btnId" />
此命令按钮使用 styleClass 表单按钮。
我在支持 bean 中有一些 boolean 成员,它会在某些事件触发后更改它的值。
是否可以根据该 boolean 值更改我的 commandButton StyleClass?
我的意思是,当这个 boolean 值变为真时,commandButton styleClass 将更改为其他样式。
感谢任何帮助,
谢谢,
约翰
最佳答案
在 styleClass
属性中使用 el 表达式和三元运算符:
<tr:commandButton text="test"
styleClass="#{bean.boolVal ? 'form-button' : 'another-style'}"
actionBean="#{testPage}" action="synchAction"
partialSubmit="true" id="btnId" />
关于java - JSF 2.0 - 更改组件样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10607290/