1

We have to visualforce components. I wanted to call the components based upon a flag on the custom object.

I ended up with the following visualforce page, which works, but since I am not really a coder, I want to verify if this is the proper thing to do or if I should have done it a different way?

<apex:page standardController="Project_Charter__c" showHeader="false" applyBodyTag="false" renderAs="pdf">
<apex:stylesheet value="{!$Resource.RP_PDF_CSS}" />
<apex:outputPanel rendered="{!(Project_Charter__c.SDPY_Format__c)}">
    <c:ProjectCharterEmailSDPY record="{!id}"/>
</apex:outputPanel>
<apex:outputPanel rendered="{!NOT(Project_Charter__c.SDPY_Format__c)}">
    <c:ProjectCharterEmail record="{!id}"/>
</apex:outputPanel>
</apex:page>
1

Looks a reasonable way to do it if the two components are substantially different. If they are nearly the same, you could avoid duplication by just conditionally rendering the parts that vary.

Also, note that the component itself can be directly conditionally rendered, so avoiding the apex:outputPanel elements:

<apex:page standardController="Project_Charter__c" showHeader="false" applyBodyTag="false" renderAs="pdf">
<apex:stylesheet value="{!$Resource.RP_PDF_CSS}" />

<c:ProjectCharterEmailSDPY record="{!id}" rendered="{!(Project_Charter__c.SDPY_Format__c)}"/>

<c:ProjectCharterEmail record="{!id}" rendered="{!NOT(Project_Charter__c.SDPY_Format__c)}"/>

</apex:page>

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.