Order of execution in Visualforce page

1. Constructor of the controller.

2. Action method of the page.

3. Getter methods.

4. If there are any client-side technologies on the page, such as JavaScript, the browser executes them. Example is window.onLoad().

Note:
If the page contains an <apex:form> component, all of the information necessary to maintain the state of the database between page requests is saved as an encrypted view state. The view state is updated whenever the page is updated.

Sample Code:

Visualforce page:

<apex:page controller="Sample" action="{!sav}">
    <apex:outputText >{!mem}</apex:outputText>
</apex:page>

Apex Controller:

public with sharing class Sample {

    public String mem {
       get { return 'getter';}  
       set;
    }

    public sample() {
        mem = 'constructor';
    }
    
    public void sav() {
        mem = 'action';
    }    

}

Output:


No comments:

Post a Comment