7

Does there exist a dynamic binding mechanism for the list attribute in the <apex:relatedList> element? I want to display a related list for a relationship that does not exist on all orgs where my managed package is installed.

I found out that this can be implemented with Dynamic Vf components but I want to be sure that there is no easier solution for this?

If dynamic components are the way to go? Does there exits an elegant (=short) example in the web?

10

Indeed Visualforce reports the List attribute as only supporting Literal values. Fortunately it is indeed possible to achieve what you want via Dynamic Visualforce. I found an example of this in the Salesforce Visualforce Developers guide here. In the code sample you can see the RelatedList component being created and the List attribute being set dynamically.

public Component.Apex.OutputPanel getClassroomRelatedLists() 
{
    Component.Apex.OutputPanel dynOutPanel= new Component.Apex.OutputPanel(); 
    for(String id: selectedNames) 
    {
       Component.Apex.RelatedList dynRelList = new Component.Apex.RelatedList();
       dynRelList.list = id;
       dynOutPanel.childComponents.add(dynRelList);
    }
    return dynOutPanel;
}
3

You are correct that this will require dynamic VF components. Anything that you would attempt to bind directly to VF markup will attempt to validate against a real schema component. When installing in an org missing the related list, it will fail.

You've probably already seen this blog entry on developerforce: http://blogs.developerforce.com/developer-relations/2011/05/dynamic-visualforce-components-in-summer-11.html

But I don't know of a lot of other resources on the web besides that for dynamic Visualforce components.

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.