0

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?

  • 1
    what exactly is the problem? doesn't it work/compile/...? does it show both panels or none? – Christoph Oct 6 '15 at 14:57
  • @Christoph sorry to leave that part out. I updated the original question but the problem s that I am only able to see the first panel (show when false) even when the checkbox is true. – John_Henry Oct 6 '15 at 15:15
  • Looks okay. Try outputting the fields value, like <apex:repeat value="{!responses}" var="response" id="responseRepeat">{!response.Checkbox__c}</apex:repeat> Check what is being shown and if the checkbox__c is really true – Christoph Oct 6 '15 at 15:25
  • 1
    Option A should do just fine – Christoph Oct 6 '15 at 15:31
  • 2
    Might be a FLS issue. You don't really need two panels for this, you can just merge in the value instead. <apex:outputPanel>{!IF(response.Checkbox__c, 'The checkbox is true', 'The checkbox is false')}</apex:outputPanel> – Adrian Larson Oct 6 '15 at 15:35
4

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> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.