+ Start a Discussion
Leuwend Job HapaLeuwend Job Hapa 

Attributes Exection Order

I have a custom component below which has many attributes:
<c:SampleComponent sortBy="Type" storeTo="page2:hidden" isTableFormat="true"/>
How will I know which of the setter methods of each attributes executes first? Thanks!
Best Answer chosen by Leuwend Job Hapa
bob_buzzardbob_buzzard
There is no guarantee on the order in which the attributes will be assigned - in fact the setters may be called more than once as well:

This is documented behaviour - see:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_methods.htm

In the setter section, it states (bold is mine):

It’s a best practice for setter methods to be idempotent, that is, to not have side effects. For example, don’t increment a variable, write a log message, or add a new record to the database. Visualforce doesn’t define the order in which setter methods are called, or how many times they might be called in the course of processing a request. Design your setter methods to produce the same outcome, whether they are called once or multiple times for a single page request.

All Answers

Ankit AroraAnkit Arora
What is the exact problem you are facing, as what I predict is you are not able to get the value in constructor? You should first know the execution order :

1. constructor methods run.
2. attributes expressions are evaluated.
3. executes any assignTo attributes.
4. evaluates action method and executes all other method calls

Some helpful links which I can gather related to this :

http://salesforce.stackexchange.com/questions/34684/getters-and-setters-order-in-a-visualforce-component
http://salesforce.stackexchange.com/questions/9941/setter-method-in-vf-component-being-called-after-the-constructor-has-retured
http://bobbuzzard.blogspot.in/2011/05/updating-attributes-in-component.html
Leuwend Job HapaLeuwend Job Hapa
My problem is that how will i know which of my attributes have been assigned a value. Can you just explain to me steps 2 and 3 with clearer details? Thanks!
bob_buzzardbob_buzzard
There is no guarantee on the order in which the attributes will be assigned - in fact the setters may be called more than once as well:

This is documented behaviour - see:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_methods.htm

In the setter section, it states (bold is mine):

It’s a best practice for setter methods to be idempotent, that is, to not have side effects. For example, don’t increment a variable, write a log message, or add a new record to the database. Visualforce doesn’t define the order in which setter methods are called, or how many times they might be called in the course of processing a request. Design your setter methods to produce the same outcome, whether they are called once or multiple times for a single page request.
This was selected as the best answer