So we have a Visualforce page:
<apex:page controller="Problem_GenerateDynamicComponent">
<c:Problem_Demonstration_1 />
<apex:dynamicComponent componentValue="{!component}" />
</apex:page>
If we run the page like this, and we check the debug logs, we see that the constructor of the Page is run before the constructor of the Components:
(Check the "Constructor of Component" and "Constructor of Page" debug messages that we put in the constructors)
34.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
16:07:05.044 (44837727)|EXECUTION_STARTED
16:07:05.044 (44873673)|CODE_UNIT_STARTED|[EXTERNAL]|066250000000Je9|VF: /apex/Problem_Demonstration_1
16:07:05.046 (46481589)|CODE_UNIT_STARTED|[EXTERNAL]|01p250000009Nus|Problem_GenerateDynamicComponent <init>
16:07:05.046 (46498858)|SYSTEM_MODE_ENTER|true
16:07:05.047 (47335826)|METHOD_ENTRY|[1]|01p250000009Nus|Problem_GenerateDynamicComponent.Problem_GenerateDynamicComponent()
16:07:05.047 (47349714)|METHOD_EXIT|[1]|Problem_GenerateDynamicComponent
16:07:05.047 (47497434)|SYSTEM_METHOD_ENTRY|[6]|System.debug(ANY)
16:07:05.047 (47528424)|USER_DEBUG|[6]|DEBUG|Constructor of Page : Problem_GenerateDynamicComponent
16:07:05.047 (47537994)|SYSTEM_METHOD_EXIT|[6]|System.debug(ANY)
16:07:05.049 (49728813)|SYSTEM_METHOD_ENTRY|[7]|Problem_GenerateDynamicComponent.__sfdc_component(ApexPages.Component)
16:07:05.049 (49762475)|SYSTEM_METHOD_EXIT|[7]|Problem_GenerateDynamicComponent.__sfdc_component(ApexPages.Component)
16:07:05.049 (49778474)|CODE_UNIT_FINISHED|Problem_GenerateDynamicComponent <init>
16:07:05.049 (49829623)|CODE_UNIT_STARTED|[EXTERNAL]|01p250000009Nus|Problem_GenerateDynamicComponent get(component)
16:07:05.049 (49838217)|SYSTEM_MODE_ENTER|true
16:07:05.049 (49856896)|CODE_UNIT_STARTED|[EXTERNAL]|01p250000009Nus|component
16:07:05.049 (49869087)|CODE_UNIT_FINISHED|component
16:07:05.049 (49881381)|CODE_UNIT_FINISHED|Problem_GenerateDynamicComponent get(component)
16:07:05.050 (50295776)|CODE_UNIT_STARTED|[EXTERNAL]|01p250000009Ntp|Problem_Demonstration_1 <init>
16:07:05.050 (50308991)|SYSTEM_MODE_ENTER|true
16:07:05.050 (50350745)|METHOD_ENTRY|[1]|01p250000009Ntp|Problem_Demonstration_1.Problem_Demonstration_1()
16:07:05.050 (50360387)|METHOD_EXIT|[1]|Problem_Demonstration_1
16:07:05.050 (50401736)|SYSTEM_METHOD_ENTRY|[22]|System.debug(ANY)
16:07:05.050 (50418267)|USER_DEBUG|[22]|DEBUG|Constructor of Component : Problem_Demonstration_1
16:07:05.050 (50425063)|SYSTEM_METHOD_EXIT|[22]|System.debug(ANY)
16:07:05.050 (50619618)|SYSTEM_METHOD_ENTRY|[24]|Problem_Demonstration_1.__sfdc_someAccount(Account)
16:07:05.050 (50650265)|SYSTEM_METHOD_EXIT|[24]|Problem_Demonstration_1.__sfdc_someAccount(Account)
16:07:05.050 (50756398)|SYSTEM_CONSTRUCTOR_ENTRY|[28]|<init>()
16:07:05.050 (50780767)|SYSTEM_CONSTRUCTOR_EXIT|[28]|<init>()
However, if we remove the dynamic component from the page, so the page becomes
<apex:page controller="Problem_GenerateDynamicComponent">
<c:Problem_Demonstration_1 />
</apex:page>
Then suddenly the constructor the Component is run before the constructor of the Page. Has anybody seen this before? And why is that?
34.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
16:06:22.040 (40634685)|EXECUTION_STARTED
16:06:22.040 (40667058)|CODE_UNIT_STARTED|[EXTERNAL]|066250000000JiG|VF: /apex/Problem_Demonstration_3
16:06:22.042 (42640889)|CODE_UNIT_STARTED|[EXTERNAL]|01p250000009Ntp|Problem_Demonstration_1 <init>
16:06:22.042 (42658248)|SYSTEM_MODE_ENTER|true
16:06:22.043 (43205424)|METHOD_ENTRY|[1]|01p250000009Ntp|Problem_Demonstration_1.Problem_Demonstration_1()
16:06:22.043 (43222573)|METHOD_EXIT|[1]|Problem_Demonstration_1
16:06:22.043 (43468175)|SYSTEM_METHOD_ENTRY|[22]|System.debug(ANY)
16:06:22.043 (43500069)|USER_DEBUG|[22]|DEBUG|Constructor of Component : Problem_Demonstration_1
16:06:22.043 (43508225)|SYSTEM_METHOD_EXIT|[22]|System.debug(ANY)
16:06:22.043 (43691101)|SYSTEM_METHOD_ENTRY|[24]|Problem_Demonstration_1.__sfdc_someAccount(Account)
16:06:22.043 (43743567)|SYSTEM_METHOD_EXIT|[24]|Problem_Demonstration_1.__sfdc_someAccount(Account)
16:06:22.043 (43825144)|SYSTEM_CONSTRUCTOR_ENTRY|[28]|<init>()
16:06:22.043 (43855761)|SYSTEM_CONSTRUCTOR_EXIT|[28]|<init>()
16:06:22.043 (43877669)|SYSTEM_METHOD_ENTRY|[28]|Problem_Demonstration_1.__sfdc_possibleProperties(List<System.SelectOption>)
16:06:22.043 (43929082)|SYSTEM_METHOD_EXIT|[28]|Problem_Demonstration_1.__sfdc_possibleProperties(List<System.SelectOption>)
16:06:22.043 (43943397)|SYSTEM_METHOD_ENTRY|[29]|Problem_Demonstration_1.__sfdc_possibleProperties()
16:06:22.043 (43995881)|SYSTEM_METHOD_EXIT|[29]|Problem_Demonstration_1.__sfdc_possibleProperties()
16:06:22.044 (44022911)|SYSTEM_METHOD_ENTRY|[29]|List<System.SelectOption>.add(Object)
16:06:22.044 (44042496)|SYSTEM_METHOD_EXIT|[29]|List<System.SelectOption>.add(Object)
16:06:22.044 (44053022)|SYSTEM_METHOD_ENTRY|[30]|Problem_Demonstration_1.__sfdc_possibleProperties()
16:06:22.044 (44072498)|SYSTEM_METHOD_EXIT|[30]|Problem_Demonstration_1.__sfdc_possibleProperties()
16:06:22.044 (44086776)|SYSTEM_METHOD_ENTRY|[30]|List<System.SelectOption>.add(Object)
16:06:22.044 (44100145)|SYSTEM_METHOD_EXIT|[30]|List<System.SelectOption>.add(Object)
16:06:22.044 (44115711)|CODE_UNIT_FINISHED|Problem_Demonstration_1 <init>
16:06:22.044 (44375180)|CODE_UNIT_STARTED|[EXTERNAL]|01p250000009Ntp|Problem_Demonstration_1 get(someAccount)
16:06:22.044 (44384546)|SYSTEM_MODE_ENTER|true
16:06:22.044 (44398607)|CODE_UNIT_STARTED|[EXTERNAL]|01p250000009Ntp|someAccount
16:06:22.044 (44410368)|CODE_UNIT_FINISHED|someAccount
16:06:22.044 (44424634)|CODE_UNIT_FINISHED|Problem_Demonstration_1 get(someAccount)
16:06:22.045 (45922546)|CODE_UNIT_STARTED|[EXTERNAL]|01p250000009Nus|Problem_GenerateDynamicComponent <init>
16:06:22.045 (45934668)|SYSTEM_MODE_ENTER|true
16:06:22.045 (45997111)|METHOD_ENTRY|[1]|01p250000009Nus|Problem_GenerateDynamicComponent.Problem_GenerateDynamicComponent()
16:06:22.046 (46010530)|METHOD_EXIT|[1]|Problem_GenerateDynamicComponent
16:06:22.046 (46096131)|SYSTEM_METHOD_ENTRY|[6]|System.debug(ANY)
16:06:22.046 (46113706)|USER_DEBUG|[6]|DEBUG|Constructor of Page : Problem_GenerateDynamicComponent
16:06:22.046 (46120600)|SYSTEM_METHOD_EXIT|[6]|System.debug(ANY)
16:06:22.048 (48441182)|SYSTEM_METHOD_ENTRY|[7]|Problem_GenerateDynamicComponent.__sfdc_component(ApexPages.Component)
16:06:22.048 (48495773)|SYSTEM_METHOD_EXIT|[7]|Problem_GenerateDynamicComponent.__sfdc_component(ApexPages.Component)