public with sharing class compCont {
public compCont() {
x = 15;
y = 50;
}
public integer x { get; set; }
public integer y { get; set; }
}
2) Setter methods
You can determine if a component is already initialized, and skip the logic if we're already initialized. This is most useful for component parameters.
public with sharing class compConv {
boolean hasInit;
public compConv() { hasInit = false; }
public void setData(String data) {
if(hasInit) return;
// Do one time init here
}
// Required to satisfy getter/setter, but we don't care.
public string getData() { return null; }
}
Maybe I am. I have a component that I want to set up the variables and not run every time
Suggestions
There are two approaches I've used that covers 100% of use cases.
1) Constructor
You can initialize data using the constructor for the controller, which won't be called during a postback.
Example:
2) Setter methods
You can determine if a component is already initialized, and skip the logic if we're already initialized. This is most useful for component parameters.
Example: