+ Start a Discussion
JaggyJaggy 

visualforce life cycle

Hi Guys,

 

I'm using following code for checking life cycle of a vf page.

public with sharing class lifecycle {
    public String s {
        get {
            System.debug('----------------In Get-------------');
            return 'Jagdeep';
        }
        set {
            System.debug('----------------In Set-------------');
        }
    }
    
    public void myact() {
        System.debug('----------------In Act-------------');
    }
}

 

<apex:page controller="lifecycle">
{!s}
<apex:form>
<apex:inputtext value="{!s}"/>
<apex:commandButton action="{!myact}" value="action"/>
</apex:form>
</apex:page>

 The log which generated after hitting action button is as follows

24.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
14:52:31.021 (21567000)|EXECUTION_STARTED
14:52:31.021 (21605000)|CODE_UNIT_STARTED|[EXTERNAL]|066U0000000X8Ey|VF: /apex/jaggy__lifecycle
14:52:31.021 (21797000)|VF_DESERIALIZE_VIEWSTATE_BEGIN|066U0000000X8Ey
14:52:31.023 (23967000)|VF_DESERIALIZE_VIEWSTATE_END
14:52:31.024 (24575000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|lifecycle get(s)
14:52:31.024 (24587000)|SYSTEM_MODE_ENTER|true
14:52:31.024 (24604000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|s
14:52:31.025 (25308000)|METHOD_ENTRY|[1]|01pU00000016Hc7|lifecycle.lifecycle()
14:52:31.025 (25381000)|SYSTEM_MODE_ENTER|false
14:52:31.025 (25389000)|SYSTEM_MODE_EXIT|false
14:52:31.025 (25396000)|METHOD_EXIT|[1]|lifecycle
14:52:31.025 (25404000)|SYSTEM_MODE_ENTER|false
14:52:31.025 (25447000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
14:52:31.025 (25471000)|ENTERING_MANAGED_PKG|
14:52:31.026 (26087000)|USER_DEBUG|[4]|DEBUG|----------------In Get-------------
14:52:31.026 (26102000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
14:52:31.026 (26114000)|SYSTEM_MODE_EXIT|false
14:52:31.026 (26125000)|CODE_UNIT_FINISHED|s
14:52:31.026 (26133000)|CODE_UNIT_FINISHED|lifecycle get(s)
14:52:31.026 (26218000)|CODE_UNIT_STARTED|[EXTERNAL]|lifecycle set(s,Jagdeep)
14:52:31.026 (26228000)|SYSTEM_MODE_ENTER|true
14:52:31.026 (26244000)|CODE_UNIT_STARTED|[EXTERNAL]|lifecycle set(s,Jagdeep)
14:52:31.026 (26322000)|SYSTEM_MODE_ENTER|false
14:52:31.026 (26341000)|SYSTEM_METHOD_ENTRY|[8]|System.debug(ANY)
14:52:31.026 (26349000)|ENTERING_MANAGED_PKG|
14:52:31.026 (26372000)|USER_DEBUG|[8]|DEBUG|----------------In Set-------------
14:52:31.026 (26379000)|SYSTEM_METHOD_EXIT|[8]|System.debug(ANY)
14:52:31.026 (26383000)|SYSTEM_MODE_EXIT|false
14:52:31.026 (26389000)|CODE_UNIT_FINISHED|lifecycle set(s,Jagdeep)
14:52:31.026 (26394000)|CODE_UNIT_FINISHED|lifecycle set(s,Jagdeep)
14:52:31.026 (26506000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|lifecycle invoke(myact)
14:52:31.026 (26542000)|SYSTEM_MODE_ENTER|false
14:52:31.026 (26556000)|SYSTEM_METHOD_ENTRY|[13]|System.debug(ANY)
14:52:31.026 (26560000)|ENTERING_MANAGED_PKG|
14:52:31.026 (26580000)|USER_DEBUG|[13]|DEBUG|----------------In Act-------------
14:52:31.026 (26587000)|SYSTEM_METHOD_EXIT|[13]|System.debug(ANY)
14:52:31.026 (26591000)|SYSTEM_MODE_EXIT|false
14:52:31.026 (26619000)|CODE_UNIT_FINISHED|lifecycle invoke(myact)
14:52:31.026 (26638000)|VF_APEX_CALL|j_id4|{!myact}|PageReference: none
14:52:31.039 (39212000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|lifecycle get(s)
14:52:31.039 (39226000)|SYSTEM_MODE_ENTER|true
14:52:31.039 (39236000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|s
14:52:31.039 (39273000)|SYSTEM_MODE_ENTER|false
14:52:31.039 (39291000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
14:52:31.039 (39296000)|ENTERING_MANAGED_PKG|
14:52:31.039 (39306000)|USER_DEBUG|[4]|DEBUG|----------------In Get-------------
14:52:31.039 (39314000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
14:52:31.039 (39319000)|SYSTEM_MODE_EXIT|false
14:52:31.039 (39327000)|CODE_UNIT_FINISHED|s
14:52:31.039 (39332000)|CODE_UNIT_FINISHED|lifecycle get(s)
14:52:31.040 (40451000)|VF_SERIALIZE_VIEWSTATE_BEGIN|066U0000000X8Ey
14:52:31.041 (41722000)|VF_SERIALIZE_VIEWSTATE_END
14:52:31.301 (44149000)|CUMULATIVE_LIMIT_USAGE
14:52:31.301|LIMIT_USAGE_FOR_NS|jaggy|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of script statements: 6 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

This log is only after action button is invoked. I dont know why it is printing '---------------in get----------------' string. Any suggestion on that.

 

 

SeAlVaSeAlVa

Hi, 

 

as you do not have any reRender in your commandButton nor any PageReference returned on the action, 

after calling the action, the page is being reloaded, what requires to 'get' all the variables again, and I believe that's why is calling the get method.

 

Regards.

kiranmutturukiranmutturu

if you call your page thorugh url or post back... all the properties will execute ...only difference is constructor will never invoke in post back calls...u can get the help here and here

JaggyJaggy

I also used rerender but it generates the same log

JaggyJaggy

kiran,

 

In the help, it is nowhere mentioned that first all getters are executed. Could you pls point that line in the help doc?

aballardaballard

You should not make any assumptions about when getters/setters get executed or how many times. 

And specifically, trying to reverse engineer it like this will get you in trouble as it may change at any time  with future features and bug fixes. 

 

(But, CURRENTLY , during the request for an "action", it will first recreate the state that existed when the page was created  -- the first get call ,  then apply changes -- the set call, then perform the action -- the act call, then generate the page  -- the second get call.  )