function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ryan GreeneRyan Greene 

Dynamically render table based on list size VF Page as PDF

Hello,
I have a vf page as PDF which pulls all of the "Additional Owners" from a Lead, and places them in a table. Right now I use the class to determine the list size like this:
public Integer add {get;set;}
    public LeadPDF(){
        AO = [SELECT Id,Name FROM Additional_Owner__c WHERE Lead__c =: Ld[0].Id];
        add = AO.size();
So then my VF Page renders the section if the size equals 1, 2, 3 and so on. Is there a better way to write this VF Page to loop and add additional spaces if needed? I could potentially have 30+ additional owners at some point and really don't want to write 30+ different tables.
Thank you!
-Ryan
VF Page table section:
<apex:outputPanel rendered="{!IF(add=1,True,False)}">
                <center><b>Additional Owner</b></center>
                <table style="width:100%">
                    <tr>
                        <th>Entity/Officer</th>
                        <th>Ownership Type</th>
                        <th>Officer Email</th>
                        <th>Phone</th>
                        <th>Ownership Percentage</th>
                    </tr>
                    <tr>
                        <td><apex:outputLabel style="color:black"><apex:outputfield value="{!AO[0].Entity_Officer__c}"/></apex:outputLabel></td>
                        <td>{!AO[0].Ownership_Type__c}</td>
                        <td>{!AO[0].Officer_Email__c}</td>
                        <td>{!AO[0].Phone__c}</td>
                        <td>{!AO[0].Ownership_Percentage__c}</td>
                    </tr>
                </table>
                </apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=2,True,False)}"><center><b>Additional Owners</b></center>
                <table style="width:100%">
                    <tr>
                        <th>Entity/Officer</th>
                        <th>Ownership Type</th>
                        <th>Officer Email</th>
                        <th>Phone</th>
                        <th>Ownership Percentage</th>
                    </tr>
                    <tr>
                        <td><apex:outputLabel style="color:black;"><apex:outputfield value="{!AO[0].Entity_Officer__c}"/></apex:outputLabel></td>
                        <td>{!AO[0].Ownership_Type__c}</td>
                        <td>{!AO[0].Officer_Email__c}</td>
                        <td>{!AO[0].Phone__c}</td>
                        <td>{!AO[0].Ownership_Percentage__c}</td>
                    </tr>
                    <tr>
                        <td><apex:outputfield value="{!AO[1].Entity_Officer__c}"/></td>
                        <td>{!AO[1].Ownership_Type__c}</td>
                        <td>{!AO[1].Officer_Email__c}</td>
                        <td>{!AO[1].Phone__c}</td>
                        <td>{!AO[1].Ownership_Percentage__c}</td>
                    </tr>
                </table>
            </apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=3,True,False)}">EXTRA TABLE SECTIONS HERE</apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=4,True,False)}">EXTRA TABLE SECTIONS HERE</apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=5,True,False)}">EXTRA TABLE SECTIONS HERE</apex:outputPanel>
Best Answer chosen by Ryan Greene
Waqar Hussain SFWaqar Hussain SF
try below VF code
 
<apex:outputPanel rendered="{!IF(add=1,True,False)}">
                <center><b>Additional Owner</b></center>
                <table style="width:100%">
                    <tr>
                        <th>Entity/Officer</th>
                        <th>Ownership Type</th>
                        <th>Officer Email</th>
                        <th>Phone</th>
                        <th>Ownership Percentage</th>
                    </tr>
					<apex:repeat value="{!AO}" var="a" >
                    <tr>
                        <td><apex:outputLabel style="color:black">
						<apex:outputfield value="{!a.Entity_Officer__c}"/></apex:outputLabel></td>
                        <td>{!a.Ownership_Type__c}</td>
                        <td>{!a.Officer_Email__c}</td>
                        <td>{!a.Phone__c}</td>
                        <td>{!a.Ownership_Percentage__c}</td>
                    </tr>
					</apex:repeat>
                </table>
                </apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=3,True,False)}">EXTRA TABLE SECTIONS HERE</apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=4,True,False)}">EXTRA TABLE SECTIONS HERE</apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=5,True,False)}">EXTRA TABLE SECTIONS HERE</apex:outputPanel>

 

All Answers

Waqar Hussain SFWaqar Hussain SF
try below VF code
 
<apex:outputPanel rendered="{!IF(add=1,True,False)}">
                <center><b>Additional Owner</b></center>
                <table style="width:100%">
                    <tr>
                        <th>Entity/Officer</th>
                        <th>Ownership Type</th>
                        <th>Officer Email</th>
                        <th>Phone</th>
                        <th>Ownership Percentage</th>
                    </tr>
					<apex:repeat value="{!AO}" var="a" >
                    <tr>
                        <td><apex:outputLabel style="color:black">
						<apex:outputfield value="{!a.Entity_Officer__c}"/></apex:outputLabel></td>
                        <td>{!a.Ownership_Type__c}</td>
                        <td>{!a.Officer_Email__c}</td>
                        <td>{!a.Phone__c}</td>
                        <td>{!a.Ownership_Percentage__c}</td>
                    </tr>
					</apex:repeat>
                </table>
                </apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=3,True,False)}">EXTRA TABLE SECTIONS HERE</apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=4,True,False)}">EXTRA TABLE SECTIONS HERE</apex:outputPanel>
            <apex:outputPanel rendered="{!IF(add=5,True,False)}">EXTRA TABLE SECTIONS HERE</apex:outputPanel>

 
This was selected as the best answer
Ryan GreeneRyan Greene
Perfect, Thanks Waqar!
Now I have just one table as follows, and updated the IF so if there is at least one Additional Owner then it will display and continue the loop through all the rest.
<apex:outputPanel rendered="{!IF(add>1,True,False)}">
                <center><b>Additional Owner</b></center>
                <table style="width:100%">
                    <tr>
                        <th>Entity/Officer</th>
                        <th>Ownership Type</th>
                        <th>Officer Email</th>
                        <th>Phone</th>
                        <th>Ownership Percentage</th>
                    </tr>
                    <apex:repeat value="{!AO}" var="a">
                    <tr>
                        <td><apex:outputLabel style="color:black"><apex:outputfield value="{!a.Entity_Officer__c}"/></apex:outputLabel></td>
                        <td>{!a.Ownership_Type__c}</td>
                        <td>{!a.Officer_Email__c}</td>
                        <td>{!a.Phone__c}</td>
                        <td>{!a.Ownership_Percentage__c}</td>
                    </tr>
                    </apex:repeat>
                </table>
                </apex:outputPanel>