A postback request is made when user interaction requires a page update, such as when a user clicks on a Save button and triggers a save action. The following diagram shows how a Visualforce page interacts with controller extension or a custom controller class during a postback request:
- During a postback request, the view state is decoded and used as the basis for updating the values on the page.
A component with the immediate attribute set to true bypasses this phase of the request. In other words, the action executes,but no validation is performed on the inputs and no data changes on the page.
- After the view state is decoded, expressions are evaluated and set methods on the controller and any controller extensions, including set methods in controllers defined for custom components, are executed.
These method calls do not update the data unless all methods are executed successfully. For example, if one of the methods updates a property and the update is not valid due to validation rules or an incorrect data type, the data is not updated and the page redisplays with the appropriate error messages.
- The action that triggered the postback request is executed. If that action completes successfully, the data is updated. If the postback request returns the user to the same page, the view state is updated.
The action attribute on the <apex:page>component is not evaluated during a postback request. It is only evaluated during a get request.
- The Resulting HTML is sent to the browser.
If the postback request indicates a page redirect and the redirect is to a page that uses the same controller and a proper subset of controller extensions of the originating page, a postback request is executed for that page. Otherwise, a get request is executed for the page. If the postback request contains an <apex:form> component, only the ID query parameter on a postback request is returned.
You can use the setRedirect attribute on a pageReference to control whether a postback or get request is executed. If setRedirect is set to true, a get request is executed. Setting it to false does not ignore the restriction that a postback request will be executed if and only if the target uses the same controller and a proper subset of extensions. If setRedirect is set to false, and the target does not meet those requirements,a get request will be made.
Once the user is redirected to another page, the view state and controller objects are deleted. For a specific example of a postback request, see Examples of Visualforce Page Execution Order.