You need to sign in to do that
Don't have an account?
Colin Loretz
Tree/List with unknown levels
Hey everyone,
I'm trying to build a tree component and am able to go down two levels but I'm not sure how (or if) it would be possible to continue adding levels.
I'm already building the above tree with the following code:
If I have any items below 1.1 or 2.1, such as 1.1.1, 1.1.1.1, etc. what would be the best way to build a list of this nature?
Thanks,
Colin
I'm trying to build a tree component and am able to go down two levels but I'm not sure how (or if) it would be possible to continue adding levels.
I'm already building the above tree with the following code:
Controller:
public ProjectTask__c [] getTasks() { return [Select Id, Name, (Select Id, Name from Tasks__r) from ProjectTask__c where Project__c = :projectId]; }
VF Page:
<ul id ="tree" class="treeview"> <apex:repeat value="{!tasks}" var="t"> <li><span class = "file"><a href = "/{!t.id}">{!t.name}</a></span> <ul> <apex:repeat value="{!t.Tasks__r}" var="st"> <li><span class = "file"><a href = "/{!st.Id}" />{!st.name}</a></span></li> </apex:repeat> </ul> </li> </apex:repeat> </ul>
If I have any items below 1.1 or 2.1, such as 1.1.1, 1.1.1.1, etc. what would be the best way to build a list of this nature?
Thanks,
Colin
I would not recommend your approach as you will not be able to dynamically add tags to your page based on multiple levels of the tree.
I would suggest to create a javascript API for your tree or you may be able to use one you already have or can get from the internet and then using your component's Controller inject javascript function calls to your page to render the tree on the screen.
This way you can do recursive method calls on the controller side to render your tree branches.
regards,
I'm going to give the YUI treeview another shot because I have seen it work for Ron Hess in one of his demonstrations.
Thanks for the tip.
Hello Colin,
I am working on an exactly similar requirement wherein i need to show the levels in a tree dynamically.
Were you able to get a solution for this?
Would be really obliged if you can help me on this!!
Many Thanks,
Cool_D
I too am working on something similar to this. I'll post again if I come up with anything cool.
hello
I am trying to build a tree view in which i want to display territory name and when we click on territory name it should expand and show users in that territory. Please help me out with this. I have a very aggressive timeline
To build a recursive tree, you'd have to build a treeNode component that calls itself recursively. Basically, it would look like this:
<apex:component controller="nodeController" selfClosing="true"> <apex:param name="nodeId" type="string" assignTo="{!nodeId}" /> <apex:commandButton action="{!togglecollapse}" /> <apex:outputText value="{!nodeText}" /> <apex:repeat value="{!nodeList}" var="node" rendered="{!nodeCollapsed}"> <c:treeNode nodeId="{!node.nodeId}" collasped={!node.collasped}" /> </apex:repeat> <apex:repeat value="{!leafList}" var="leaf"> <apex:commandLink action="{!leaf.action}" value="{!leaf.label}" /> </apex:repeat> </apex:component>
Are you sure you can do recursive components? I've tried to do this in the past but always got a "Save error: Failed Validation: ApexComponent" when I tried to do recursion with components.
Scott
Hey,
I just now tried recursing Apex components and I also get a 'Validation Failed' error upon compile. So nothing's changed on that front.
In an attempt to be clever, I created a component wrapper and used that to indirectly recurse - exact same desired result but now the component doesn't have to explicitly refer to itself. But when I try to render the page that contains the component, it tells me "An internal server error has occurred", which I take to mean that I'm out of luck.
Time to start thinking about a JS implementation.........