I'm trying to create a customized version of the campaign hierarchy page, allowing for the display of additional data other than just campaign names. I have a Map<ID, List<Campaign>>
keyed with the ID of a parent campaign and valued with a list of direct child campaigns of the keyed parent. There is one null key in the map that correlates to a list with only one element, that element being the root campaign from which the hierarchy begins. The assumption can be made that every campaign represented in one of the value lists is also represented as a key, which may or may not correlate to an empty list (depending on whether that campaign has any direct children).
Here's a simple, concrete example of the map described above:
{
null=>(Campaign:{Name=Parent, Id=701180000000luvAAA})
701180000000luvAAA=>(Campaign:{Name=Child 1, Id=701180000000luwAAA}, Campaign:{Name=Child 2, Id=701180000000luxAAA})
701180000000luwAAA=>(Campaign:{Name=Grandchild, Id=701180000000luyAAA})
701180000000luxAAA=>()
701180000000luyAAA=>()
}
Given that map, I have a recursive method that traverses down each line of descendants beginning with the root (imagine the pre-order navigation of a tree structure):
// Populated campaign map
private Map<ID, List<Campaign>> campaignsByParent;
public void displayCampaignsRecursively(ID parentId) {
List<Campaign> childCampaigns = this.campaignsByParent.get(parentId);
for (Campaign c : childCampaigns) {
// Display campaign here
this.displayCampaignsRecursively(c.Id);
}
}
which I can call like:
// Root campaign does not have a parent, so parent ID is null to start.
ID rootCampaignParentId = null;
Controller.displayCampaignsRecursively(rootCampaignParentId);
The problem is I'm not sure how to actually display the campaigns. I want to display the data in an <apex:pageBlock>
, but I know I can't just bind the map to an <apex:repeat>
control since the order of elements can change. How can I do this? Any and all ideas are appreciated!