9

I have page

<apex:page controller="myController1" action="{!actionmethod}">

<c:compo value="hello"></c:compo> 

</apex:page>

Controller mycontroller1 class code is below

public with sharing class myController1 {

public void actionmethod()

{
system.debug('ACTIONMETHOD');
}
}

My component compo is as below

<apex:component controller="compocontroller">
<apex:attribute name="value" type="string" description="tu" assignTo="{!valueclassvar}"/>
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Component
  <!-- End Default Content REMOVE THIS -->
</apex:component>

Its controller compocontroller is

 public class compocontroller   
    {
    public  string valueclassvar
  {
    get{
        system.debug('getmethod '+valueclassvar); 
        return valueclassvar;
        }
     set{ 
        system.debug('setmethodfirst'+ valueclassvar);
        valueclassvar = value;
        system.debug('setmethod'+ valueclassvar);
  }
       }

public compocontroller()
{    
system.debug('componentconstructor');
system.debug( valueclassvar);
}

}

Now issue is as per order of execution of VF page i expected first constructors of controllers/ext controllers to execute first followed by component's constructor if any.Then only action method/experession/getset(in randomn order) gets priority

When i look at debug log for this code,i can see action method getting executed soon after constructor of main class why is that so?Debug log is

30.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
11:11:30.042 (42146795)|EXECUTION_STARTED
11:11:30.042 (42206001)|CODE_UNIT_STARTED|[EXTERNAL]|066i0000004EBS1|VF: /apex/orderofexe
11:11:30.059 (59813931)|CODE_UNIT_STARTED|[EXTERNAL]|01pi0000005tsxw|myController1 <init>
11:11:30.059 (59842210)|SYSTEM_MODE_ENTER|true
11:11:30.060 (60713868)|METHOD_ENTRY|[1]|01pi0000005tsxw|myController1.myController1()
11:11:30.060 (60797146)|SYSTEM_MODE_ENTER|false
11:11:30.060 (60807508)|SYSTEM_MODE_EXIT|false
11:11:30.060 (60819362)|METHOD_EXIT|[1]|myController1
11:11:30.060 (60844660)|SYSTEM_MODE_ENTER|false
11:11:30.060 (60863778)|SYSTEM_MODE_EXIT|false
11:11:30.060 (60869452)|SYSTEM_MODE_ENTER|false
11:11:30.060 (60872642)|SYSTEM_MODE_EXIT|false
11:11:30.060 (60888145)|CODE_UNIT_FINISHED|myController1 <init>
11:11:30.060 (60977531)|CODE_UNIT_STARTED|[EXTERNAL]|01pi0000005tsxw|myController1 invoke(actionmethod)
11:11:30.061 (61027224)|SYSTEM_MODE_ENTER|false
11:11:30.061 (61064073)|SYSTEM_METHOD_ENTRY|[6]|System.debug(ANY)
11:11:30.061 (61093925)|USER_DEBUG|[6]|DEBUG|ACTIONMETHOD
11:11:30.061 (61102290)|SYSTEM_METHOD_EXIT|[6]|System.debug(ANY)
11:11:30.061 (61107804)|SYSTEM_MODE_EXIT|false
11:11:30.061 (61141605)|CODE_UNIT_FINISHED|myController1 invoke(actionmethod)
11:11:30.061 (61190978)|VF_APEX_CALL|j_id0|{!actionmethod}|PageReference: none
11:11:30.067 (67208323)|CODE_UNIT_STARTED|[EXTERNAL]|01pi0000005trqA|compocontroller <init>
11:11:30.067 (67233044)|SYSTEM_MODE_ENTER|true
11:11:30.067 (67306289)|METHOD_ENTRY|[1]|01pi0000005trqA|compocontroller.compocontroller()
11:11:30.067 (67320158)|METHOD_EXIT|[1]|compocontroller
11:11:30.067 (67376097)|SYSTEM_METHOD_ENTRY|[8]|System.debug(ANY)
11:11:30.067 (67418075)|USER_DEBUG|[8]|DEBUG|componentconstructor
11:11:30.067 (67427228)|SYSTEM_METHOD_EXIT|[8]|System.debug(ANY)
11:11:30.067 (67442037)|METHOD_ENTRY|[9]|01pi0000005trqA|compocontroller.__sfdc_valueclassvar()
11:11:30.067 (67481727)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
11:11:30.067 (67498526)|USER_DEBUG|[4]|DEBUG|getmethod null
11:11:30.067 (67505165)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
11:11:30.067 (67514592)|METHOD_EXIT|[9]|01pi0000005trqA|compocontroller.__sfdc_valueclassvar()
11:11:30.067 (67522573)|SYSTEM_METHOD_ENTRY|[9]|System.debug(ANY)
11:11:30.067 (67527466)|USER_DEBUG|[9]|DEBUG|null
11:11:30.067 (67532135)|SYSTEM_METHOD_EXIT|[9]|System.debug(ANY)
11:11:30.067 (67546445)|CODE_UNIT_FINISHED|compocontroller <init>
11:11:30.067 (67707938)|CODE_UNIT_STARTED|[EXTERNAL]|compocontroller set(valueclassvar,hello)
11:11:30.067 (67717432)|SYSTEM_MODE_ENTER|true
11:11:30.067 (67730382)|CODE_UNIT_STARTED|[EXTERNAL]|compocontroller set(valueclassvar,hello)
11:11:30.067 (67801649)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
11:11:30.067 (67810862)|USER_DEBUG|[4]|DEBUG|setmethodfirstnull
11:11:30.067 (67816332)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
11:11:30.067 (67833047)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
11:11:30.067 (67838803)|USER_DEBUG|[4]|DEBUG|setmethodhello
5

One of the things you can do in the apex:page action is to return a different PageReference and so go to a new page without rendering the body of the apex:page. Given that possibility, it makes no sense to execute component constructors before that action is executed as that could well be wasted work.

Also as parts of pages can be conditionally rendered, it may be that the component constructor is only executed if the component is actually output which would not be discovered until much later in the page execution than the evaluation of the opening apex:page element.

  • I can understand your logic..but why the documentation says otherwise.salesforce.com/us/developer/docs/pages/Content/… chart here clearly says soon after constructors check whether component is there and go for its constructors – sfdc99999 May 9 '14 at 21:00
  • @sfdc99999 Yes I agree with you that salesforce.com/docs/developer/pages/Content/… says the component constructors should run first. You could use the "Was this information helpful?" section at the bottom of the documentation to flag that the documentation may be wrong: perhaps the code has been optimised further since the documentation was written? Presumably this is an academic point and your intended code will work whatever the execution order is? – Keith C May 9 '14 at 21:10
  • yeah i am just learning whats the correct execution order.:).. – sfdc99999 May 9 '14 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.