Compound condition in visualforce

As a Salesforce developer most of the times we have encountered with rendering a block or field based on a compound condition ie., rendering a field or block based on values in different controller variables. 

This little snippet will tell you how to add a compound (multiple ) condition in a Visualforce page.

 

<apex:outputPanel rendered="{! OR( AND(var1 != null , list1.size > 0 ) , AND(var12 != null , list2.size > 0) )}">
     <!-- items in the block -->
</apex:outputPanel>

<!-- The above condition can also be written as -->

<apex:outputPanel rendered="{! ( var1 != null && list1.size > 0 ) || (var12 != null && list2.size > 0)}">
     <!-- items in the block -->
</apex:outputPanel>

 

The above condition does the same thing as the below snippet

if( (var1 != null && list1.size() > 0) || (var12 != null && list2.size() > 0) ){
   //If block logic
}

If you are familiar with apex, you can easily understand the above condition.

If you want any clarification please let me know in comments.

Happy coding... laugh

Rating: 
No votes yet