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 controller is executed even though rendered=false

I have a visualforce page that has a custom component with rendered=false.  In a different pageBlockSection, I have an inlineEditSupport component.

The problem is that when the page loads, it executes the constructor and methods of the custom component's controller.   I wouldn't expect it to do that since rendered=false.


If I remove the inlineEditSupport component and reload the page, it does not execute the custom component controller.


How can I prevent my custom component controller from executing while keeping the inlineEditSupport on the page? Rendered=false does not seem to work.


Here is the (simplified) code:


1. Custom Component Controller

public class componentController {
	public List<account> accounts{
			system.debug('in accounts getter');				
			return new List<account>();
	public componentController(){
		system.debug('in constructor');


2. Custom Component

<apex:component controller="componentController">
	<apex:pageBlockSection >
	    <apex:pageBlockTable value="{!accounts}" var="a">
	    	<apex:column >
	        	<apex:outputField value="{!}"/>


3. Visualforce Page

<apex:page controller="myController" tabStyle="Account">
    <apex:pageBlock >
        <apex:form >
            <apex:pageBlockSection >
                <apex:outputField value="{!}" />
                <apex:outputField value="{!account.NumberOfEmployees}" />
                <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick"/>
            <apex:pageBlockSection columns="1">
                <c:editMode rendered="false" />


When the above vf page loads, the debug log will include the "in constructor" and "in accounts getter" statements.  

If I remove the inlineEditSupport from the page and refresh, the debug log will not include those statements.


Any ideas?


I'm not sure "rendered" is a valid component tag attribute.  If you put the component reference inside an <apex:outputPanel > like below, you may get the result you're looking for.


<apex:outputPanel rendered="false">
    <c:editMode rendered="false" />




"rendered" is a valid attribute.  See the docs.  Putting the component inside an <apex:outputPanel>  did not make any difference.  It still called the constructor and methods on the controller.  There is a similar question here.