Playing around with Dynamic Visualforce Components I found it inconvenient to create child elements in such a bulky notation
public Component.Apex.OutputPanel getNavPanel1(){
Component.Apex.OutputPanel p = new Component.Apex.OutputPanel();
p.childComponents.add( new Component.Apex.OutputText( value = 'test_dummy_text_1' ) );
p.childComponents.add( new Component.Apex.OutputText( value = 'test_dummy_text_2' ) );
p.childComponents.add( new Component.Apex.OutputText( value = 'test_dummy_text_3' ) );
return p;
}
I would prefer a notation like that (which does not work):
public Component.Apex.OutputPanel getNavPanel2(){
return new Component.Apex.OutputPanel( childComponents = new ApexPages.Component[]{
new Component.Apex.OutputText( value = 'test_dummy_text_1' )
,new Component.Apex.OutputText( value = 'test_dummy_text_2' )
,new Component.Apex.OutputText( value = 'test_dummy_text_3' )
});
}
Looking at the documentation here https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_dynamic_components.htm#apex_ApexPages_Component_childComponents it should be possible because it's defined as
public List <ApexPages.Component> childComponents {get; set;}
Any ideas why this does not work?
If we add at getNavPanel1()
a line like this before the return
p.childComponents = new ApexPages.Component[]{}
we get at least a hint form the compiler: "Variable is not visible: childComponents" - but why? If it's a public property as defined, it should be writable. Or do I get this wrong?