You need to sign in to do that
Don't have an account?
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{ get{ system.debug('in accounts getter'); return new List<account>(); } set; } 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="{!a.name}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:component>
3. Visualforce Page
<apex:page controller="myController" tabStyle="Account"> <apex:pageBlock > <apex:form > <apex:pageBlockSection > <apex:outputField value="{!account.name}" /> <apex:outputField value="{!account.NumberOfEmployees}" /> <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick"/> </apex:pageBlockSection> <apex:pageBlockSection columns="1"> <c:editMode rendered="false" /> </apex:pageBlockSection> </apex:form> </apex:pageBlock> </apex:page>
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.
"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.