+ Start a Discussion
Justin MitchellJustin Mitchell 

How can I pass styleClass logic to a Visualforce page from a controller?

Maybe I'm going about this wrong, but here's what I want to do:
I have a table on a visualforce page. Each column needs to be formatted conditionally based upon the "Status__c" field.
I have a class called "open". If the value of status__c = "open", then the class (styleClass) of the row should be "open". If the value of status__c is not "open", then the styleClass value should be null.

I know how to do this already inline on the visualforce page, and it works perfectly:
<apex:column value="{! ws.Name }" styleClass="{! CASE( ws.Status__c, 'Open', 'open', '' ) }" />
However, I want to move this logic to the controller and then reference it. In reality, the logic is much longer and more complext than this, so I don't want to have to repeat it over and over. Here is what I have tried and it is not working:

Controller:
public String getStyleLogic() {
        return '{! CASE( ws.Status__c, \'Open\', \'open\', \'\' )}';}
Visualforce:
<apex:column value="{! ws.Name }" styleClass="{! StyleLogic }">
 What is confusing me, is if I just put "{! StyleLogic }" at the bottom of the page, I get this result displayed:
{! CASE( ws.Status__c, 'Open', 'open', '' ) }
so my string is successfully being passed from the controller to the Visualforce page, however it is not letting me use that string as a styleClass. It is even more confusing, because if I change the StyleLogic variable to just say " return 'open' " (instead of the CASE statement) it works, and the whole column is formatted using the "open" class. 

What am I missing here?