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
Anand@SAASAnand@SAAS 

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')}"/>
   	</apex:outputPanel>
</apex:outputPanel>                
</apex:form>

</apex:page>

 

ShowEarningOpportunity method is below:

 

public PageReference showEarningOpportunity(){
	this.showEarningOppty=true;
	return null;
}

 

 

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

 

NaishadhNaishadh

Try this 

 

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

 

 

Anand@SAASAnand@SAAS

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.

geetageeta

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?

JBirkJBirk

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

 

so:

 

<apex:outputpanel rendered="false">

<c:component rendered="false">

</apex:outputpanel>

 

May keep the component controller code from executed completely.

rm1rm1

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?