+ Start a Discussion
FinnArildFluidoFinnArildFluido 

Nested dynamic custom controllers problem

I need to nest 3 levels of dynamic components. However I am running into a strange problem with the setting of attributes. It seems that the attributes are not set before after my dynamic component is called - this is regardless of where my dynamic component is called in the page. It only seems to be the case with a custom component calling another custom component.

 

Yeah - it's a bit complicated - behold the following code which should explain it more clearly:

 

<apex:page controller="pageController">
    <apex:dynamicComponent componentValue="comp1"/>
</apex:page>

public class pageController {
    public ApexPages.Component comp1 {
	get {
	    comp1 = new Component.c.nest1cont(oneval='MYSTRING');
	    return comp1
	}
	private set;
    }

<apex:component controller="nest1cont">
    <apex:attribute name="oneval" type="String" assignto="{!onevalue}"/>
    Even though this is called before dynamic component, this is not null: {!onevalue}
    <apex:dynamicComponent componentValue="comp2"/>
</apex:component>

public class nest1cont {
    public String onevalue {get;set;}

    public ApexPages.Component comp2 {
	get {
	    comp2 = new Component.c.nest2cont(twoval=onevalue);
	    System.debug('### problem is that this is not set before dynamicComponent is called: ' + onevalue);
	}
	private set;
    }
}

<apex:component controller="nest2cont">
    <apex:attribute name="twoval" type="String" assignto="{!twovalue}"/>
    This is null: {!twovalue}
</apex:component>

public class nest2cont {
    public String twovalue {get;set;}
}

 So you see I have a problem getting that variable all the way to the last nested component since it seems to call the dynamic component "nest2cont" before it sets the attribute "onevalue".

Is this a bug, or just a quirk of execution order? Does anyone have a workaround for it?