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

Custom Component constructor called even if "Rendered" =false

will a custom component controller 's constructor get called even if the "Rendered" expression evaluates to "false"? Below is a visual force page that has two components. Only one of them is rendered depending on the user's Profile name:


<apex:page showHeader="true" sidebar="false" controller="SiteHeaderController" action="{!init}">
<apex:form >
User Profile:{!userProfile}<br/>
<apex:outputText value="SL Component" rendered="{!userProfile='Leader'}"/><br/>
<apex:outputText value="ZoneDiv Component" rendered="{!OR(userProfile='Division Manager',userProfile='Zone Manager')}"/><br/>
<apex:commandLink value="{!$Label.Earning_Opportunity}" action="{!showEarningOpportunity}" rerender="earningOpportunity" rendered="{!userProfile='Leader'}"/>
<apex:outputPanel id="earningOpportunity">
   	<apex:outputPanel rendered="{!showEarningOppty}">
    	<c:SalesLeaderEarningOpportunity rendered="{!userProfile='Leader'}"/>
    	<c:ZoneDivEarningOpportunity rendered="{!OR(userProfile='Division Manager',userProfile='Avon Zone Manager')}"/>



ShowEarningOpportunity method is below:


public PageReference showEarningOpportunity(){
	return null;



When I executed the page and click on the "command link", both constructors are getting called. Am I missing something?



Try this 


<apex:outputPanel id="SLPanel" rendered="{!userProfile == 'Avon Leader'}">
      <apex:outputText value="SL Component"/><br/>




I don't think the issue is with "=" or "==". My outputText works fine and only displays the text corresponding to the user type. My issue is that the component controller's constructor is getting called.


Hi Anand,


Since you are using a controller variable to determine the rendered value, i think it will call the constructor. Can you not use the VF global variable {!$Profile.Name} to check for the profile names?


You can also try wrapping the components within another outputpanel and set the render to that accordingly,




<apex:outputpanel rendered="false">

<c:component rendered="false">



May keep the component controller code from executed completely.


I recently posted a similar question.  I found that the component controller's constructor didn't get called when "rendered" evaluated to false.  However, when I added an inlineEditSupport component to the page, the constructors did get called. Did you ever figure this one out?