[SalesForce] Conditionally Showing an apex:outputPanel

On a custom VF page, inside of an apex:repeat component I have two apex:outputPanel components. I want to show one apex:outputPanel when a checkbox field on the record is true/checked and I want to show the other when the checkbox field is false/unchecked. This seems easy enough to do but I'm getting hung up on the exact syntax.

I've tried using the field itself:

<apex:repeat value="{!responses}" var="response" id="responseRepeat">
    <!-- show when false -->
    <apex:outputPanel rendered="{!NOT(response.Checkbox__c)}">
    The checkbox is false
    </apex:outputPanel>
    <!-- show when true -->
    <apex:outputPanel rendered="{!response.Checkbox__c}">
    The checkbox is true
    </apex:outputPanel>
</apex:repeat>

checking if the field is true or false:

<apex:repeat value="{!responses}" var="response" id="responseRepeat">
    <!-- show when false -->
    <apex:outputPanel rendered="{!response.Checkbox__c == False}">
    The checkbox is false
    </apex:outputPanel>
    <!-- show when true -->
    <apex:outputPanel rendered="{!response.Checkbox__c == True}">
    The checkbox is true
    </apex:outputPanel>
</apex:repeat>

and an IF statement:

<apex:repeat value="{!responses}" var="response" id="responseRepeat">
    <!-- show when false -->
    <apex:outputPanel rendered="{!IF(response.Checkbox__c == False, true, false)}">
    The checkbox is false
    </apex:outputPanel>
    <!-- show when true -->
    <apex:outputPanel rendered="{!IF(response.Checkbox__c == True, true, false)}">
    The checkbox is true
    </apex:outputPanel>
</apex:repeat>

But no luck so far as I am only able to see the first panel (show when false) even when the checkbox is true. Any suggestions on what I'm doing wrong?

Best Answer

If you do not have Read access to the field, it will always appear false (or perhaps null would be more accurate). As a side note, you do not need two outputPanel tags. Just use:

<apex:outputPanel>
    {!IF(response.Checkbox__c, 'The checkbox is true', 'The checkbox is false')}
</apex:outputPanel> 
Related Topic