AssignTo variable in attribute

The attribute in the component is evaluated after the component's controller constructor runs. Within the constructor it will be null because it simply hasn't been evaluated yet.

You can see it here in the SFDC docs about the order of execution for VF pages on step 2.

enter image description here


Yes, the value is null in the constructor-- the value is set sometime afterwards. Usually, I do something like this:

public class RecordDisplayController {
    SObject theRecord;
    public void setObjectVar(SObject record) {
        theRecord = record;
    }
    public SObject getObjectVar() {
        return theRecord;
    }
}

You can do additional stuff in setObjectVar, like query additional fields or populate additional data. Since setters may be called more than once, you may need to "guard" against multiple sets:

public void setObjectVar(SObject record) {
    if(theRecord == null && record != null) {
        // Do stuff here
    }
}