Multiple Conditionals in rendered Attribute


scotthung

A VisualForce page can use apex:outputText component’s rendered attribute to display a text block based on different criteria.  In my case, the text block would only display if a field was not empty. For example:

<apex:outputText rendered="{!Download_URL1__c != ''}">
  text block
</apex:outputText>

If you’re familiar with VisualForce dynamic binding then you know this fetches the Download_URL1__c custom field from the object and we check that it’s not blank.

A new requirement arose to display the text block if either this, or a new second field, was not empty.  Turns out, the rendered attribute can be something akin to a formula field.  Once I discovered this, it was straightforward to update the rendered attribute to:

<apex:outputText rendered="{!OR(Download_URL1__c != '',Download_URL2__c != '')}">
  text block
</apex:outputText>

So now, if either Download_URL1__c or Download__URL2__c is not blank then the text block appears.

View original post

Advertisements