You need to sign in to do that
Don't have an account?
Why is the constructor executing twice with a component?
I have an apex component in which the constructor in the controller is exectuting twice. I have made all the pages and classes as simple as possible to reproduce and this is what we have:
The Page
<apex:page > <c:myComponent /> </apex:page>
The Component
<apex:component controller="MyController" > <apex:form > <apex:actionFunction name="thisIsMyName" action="{!doSomething}" /> </apex:form> </apex:component>
The Controller
public class MyController { //Constructor public MyController(){ system.debug('I am a constructor and I am executing multiple times to drive you crazy.'); } public void doSomething(){ //Blah blah blah } }
The Debug Log
23.0 APEX_CODE,DEBUG 18:56:46.028 (28871000)|EXECUTION_STARTED 18:56:46.028 (28903000)|CODE_UNIT_STARTED|[EXTERNAL]|066500000008tEE|VF: /apex/mypage 18:56:46.039 (39198000)|CODE_UNIT_STARTED|[EXTERNAL]|01p50000000DYoB|MyController <init> 18:56:46.039 (39850000)|METHOD_ENTRY|[1]|01p50000000DYoB|MyController.MyController() 18:56:46.039 (39939000)|METHOD_EXIT|[1]|MyController 18:56:46.041 (41245000)|USER_DEBUG|[5]|DEBUG|I am a constructor and I am executing multiple times to drive you crazy. 18:56:46.041 (41308000)|CODE_UNIT_FINISHED|MyController <init> 18:56:46.041 (41830000)|CODE_UNIT_STARTED|[EXTERNAL]|01p50000000DYoB|MyController <init> 18:56:46.041 (41872000)|USER_DEBUG|[5]|DEBUG|I am a constructor and I am executing multiple times to drive you crazy. 18:56:46.041 (41894000)|CODE_UNIT_FINISHED|MyController <init> 18:56:46.071 (71248000)|CODE_UNIT_FINISHED|VF: /apex/mypage 18:56:46.071 (71263000)|EXECUTION_FINISHED
Any ideas why this is happening. It is making me go a little crazy.
If I move everything that is in the component directly to the page it will only execute once, as expected, but I need use components.
Thanks,
Jason
Hi,
Have you found a workaround for this? Please let us know.
I am facing the same issue.
Thanks,
Devendra
In this case, is the same constructor.
To avoid this, use a different contructor in the page and in the component
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_lifecycle_example.htm