setStyleClass using conditions

Sorry for another question, but here it is:

Is it possible to call setStyleClass and pass a conditional expression? For instance, on all static JSPs in our system, a line like this works perfectly:

styleClass ="#{myBB.rowIndex == myBB.sortedModel.rowIndex ? 'selectedStyleBlue' : ''}"

However, if I am using a dynamic datatable and calling setStyleClass as

detailText.setStyleClass("#{myBB.rowIndex == myBB.sortedModel.rowIndex ? 'selectedStyleBlue' : ''}");

it completely ignores the styleClass. Moreover, if I call it like this, it works:

detailText.setStyleClass("selectedStyleBlue");

detailText is an instance of HtmlOutputText. What am I doing wrong?

[789 byte] By [Bart69a] at [2007-10-3 9:16:23]
# 1

You have to create a ValueBinding instead of a String.

ValueBinding styleClass =

FacesContext

.getCurrentInstance()

.getApplication()

.createValueBinding("#{myBB.rowIndex == myBB.sortedModel.rowIndex ? 'selectedStyleBlue' : ''}");

detailText.setStyleClass(styleClass);

BalusCa at 2007-7-15 4:29:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
setStyleClass accepts a String as a parameter though. I cannot pass a ValueBinding to this method in my version of JSF
Bart69a at 2007-7-15 4:29:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
I called setValueBinding("styleClass", styleClass) and that worked. Thank you so much!
Bart69a at 2007-7-15 4:29:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...