+ Start a Discussion

how can i display a block in if statement

Hello everybody,


Is possible display a blockTable in the if statement. Please tell me how can I do that?



Dhaval PanchalDhaval Panchal
Give your requirement. Do you want to display page block table based on criteria? If yes then you can use property "rendered".

So talking about if statement  in VF they can help you decide what value should be returned when a satement is true. More like a ternary operator.


I don't think you can insert a whole page blocktable inside a IF block. Well I dont even can think of it. I am assuming you are having a complex logic. But I guess rendered will be more than enough to display things.


so lets say.

  • When Case.Status == 'Open' display table 1
  • Case.Status = 'Closed' display table 2

Then VF will be pretty simple believe me.


<apex:pageblockTable rendered="{!Case.Status == 'Open'}" id="table1".......

<apex:pageblockTable rendered="{!Case.Status == 'Closed'}" id="table2".......



Hi There are a lot of solution for it. You can rerender or you can use some style to hide or show block on the basis of required criteriea.


Thanks all for your answers, the thing is that I have the following results

Name Contact
Benefits (Other table)

But, when the contact don't have Benefits, I don't want take the contact, I don't want show the table empty, only with your name.

How can I do that, please help me.

This is the code in my apex class


    public List<Contact> getBeneficiosUsd()
       Contact[] contactos = [SELECT contact.Name, (SELECT Name, Moneda__c, Monto_Dolares__c, proposito__c, Contacto__c, fecha_entrega__c, Catalogo_Beneficio__c FROM contact.Beneficios__r WHERE Moneda__c = :idMonedausd) FROM contact where Sayana__c = :idSayana];
       return contactos;


And this is my vf page


  <apex:pageBlock title="Beneficios Dolares">
       <table border="0" >
         <apex:repeat var="beneficio" value="{!BeneficiosUsd}">
                <th style="width: 55px;">Beneficiario:</th>
                <td colspan="2">
                    <apex:pageBlockTable value="{!beneficio.Beneficios__r}" var="c" cellPadding="3" border="1" columnsWidth="50px,110px,60px,60px,230px" rules="all">
                        <apex:column value="{!c.Name}"/>
                        <apex:column value="{!c.Catalogo_Beneficio__c}"/>
                        <apex:column value="{!c.Moneda__c}"/>
                        <apex:column value="{!c.Monto_Dolares__c}" style="text-align: right;"/>
                        <apex:column value="{!c.proposito__c}"/>                        
                        <apex:column value="{!c.fecha_entrega__c}"/>