8

Situation

I want to implement a dynamic, dynamic custom component in visualforce and apex. Therefore I created a new component:

<apex:component controller="SidebarController">
    <apex:repeat value="{!components}" var="component">
        <apex:dynamicComponent componentValue="{!component}" />
    </apex:repeat>
</apex:component>

And a corresponding controller:

public without sharing class SidebarController
{
    public List<Component.c> components {get; set;}

    public SidebarController()
    {
        components = new List<Component.c>();

        components.add(new Component.c.TestComponent());
        components.add(new Component.c.TestComponent2());
    }
}

Do you know from which type the component value has to be?

I already tried the following types:

  1. Object -> Cast fail
  2. UIComponent -> Not available in apex
  3. Component.c -> core.apexpages.quickfix.QuickFixException
  4. Component.apex -> core.apexpages.quickfix.QuickFixException
  5. Component -> general issue

Do you know the correct type of a component in apex?

  • If your dynamic components will allow input, be aware of Field Values In Dynamic Component Not Retaining After Error - the normal error handling lifecyle is broken. – Keith C Aug 18 '14 at 16:31
  • Hmm ... The doc uses Component.Apex.xxx if the component being returned is apex.xxx; in your case, you are looking for the super class above Component.Apex.xxx - and it is not Component.Apex as that causes a compile error. The SFDC example similar to what you are doing enumerates each component by type explicitly and adds to the childComponents property: salesforce.com/us/developer/docs/pages/… . The childComponents property acts as a reference to a List of Component.Apex objects. – cropredy Aug 18 '14 at 18:26
11

I think this is the correct type:

public List <ApexPages.Component> childComponents {get; set;}

Here are the docs.

| improve this answer | |
  • No problem. That happens to me all the time. :) – Peter Knolle Aug 19 '14 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.