-
1. Re: trying to get Tree component to work.
viggo.navarsete Aug 22, 2007 2:02 PM (in response to jgreene)I've also used the Library,Artist etc as the example when I developed my own tree today. I have a tree with at least four leves, and it works. I had also some initial problems, but it was caused by not setting the parent correctly in all classes implementing the TreeNode interface. Go through all your node implementations once more, and compare them to the Library,Artists examples, and I'm sure you will find what your're doing wrong :)
Or, post the node implementation classes here and we can have a look at it:) -
2. Re: trying to get Tree component to work.
jgreene Aug 22, 2007 2:42 PM (in response to jgreene)Thanks, Viggo.
I went thru my code again. I did something intentionally, but am not sure if it could be a problem. The parent nodes look to be set correctly througout, but I can post later if needed. The problem I may see now is that I may have taken too many liberties with the root node (the "Library" node). I did not completely build the structure because I simply wanted to display the first level, then expand after getting it working. Here's the code for my top level node:public class ScenarioTree implements TreeNode { private static final long serialVersionUID = -3530085227471752526L; private Object state1; private Object state2; private long nextId = 0; private Map<Object,TreeNode> iconGroupContainerCache = new HashMap<Object,TreeNode>(); private Map<Object,TreeNode> getIconGroupContainers() { if(this.iconGroupContainerCache == null) { initData(); } return this.iconGroupContainerCache; } public void addIconGroupContainer(IconGroupContainer igc) { addChild(Long.toString(igc.getId()), igc); igc.setParent(this); } public void addChild(Object identifier, TreeNode child) { getIconGroupContainers().put(identifier, child); } public TreeNode getChild(Object id) { return (TreeNode)getIconGroupContainers().get(id); } public Iterator getChildren() { return getIconGroupContainers().entrySet().iterator(); } public Object getData() { return this; } public TreeNode getParent() { return null; } public boolean isLeaf() { return getIconGroupContainers().isEmpty(); } public void removeChild(Object id) { getIconGroupContainers().remove(id); } public void setData(Object data) { } public void setParent(TreeNode parent) { } public String getType() { return "scenario tree"; } private long getNextId() { return nextId++; } private void initData() { System.out.println("Initializing Scenario Tree"); IconGroupContainer igc1 = new IconGroupContainer(1); igc1.setName("Scenario Objects"); System.out.println("Created icon group container"); IconGroupContainer igc2 = new IconGroupContainer(2); igc2.setName("Service Groups"); System.out.println("Created icon group container"); IconGroupContainer igc3 = new IconGroupContainer(3); igc3.setName("User Groups"); System.out.println("Created icon group container"); iconGroupContainerCache.put(igc1.getName(), igc1); iconGroupContainerCache.put(igc2.getName(), igc2); iconGroupContainerCache.put(igc3.getName(), igc3); System.out.println("Size = " + iconGroupContainerCache.size()); } public Object getState1() { return state1; } public void setState1(Object state1) { this.state1 = state1; } public Object getState2() { return state2; } public void setState2(Object state2) { this.state2 = state2; } }
I did not keep both the "artists" and "artistCache" maps - I only used one (I called it "iconGroupContainerCache"). For my purposes, I don't know if this would be a problem. If you don't see any issues with this code, I can post the other 3 classes. Thanks for your help. -
3. Re: trying to get Tree component to work.
viggo.navarsete Aug 22, 2007 2:55 PM (in response to jgreene)I'm not sure if you can return a type like you do. It's the type you refer to in your jsp when you say what kind of node you want. How do define the tree in your jsp? I didn't use any of the cache-things from the example, but I didn't remove the state objects, don't know what they're good for.
The rest of the code looks ok, so I'm not sure why it doesn't work.! I also took some shortcuts with the root node in the first place, but had to adjust to the examples to make it work. Try to return a type that's not two words, but one, like "scenarioTree" and refer to it in the jsp.
here is my tree defined in my jsp:<r:tree value="#{searchBean.searchResultNode.data}" var="item" nodeFace="#{item.type}"> <r:treeNode type="searchResultNode"> <h:selectBooleanCheckbox value="#item.selected"/> <h:outputText value="#{item.type}" /> </r:treeNode> <r:treeNode type="entityNode"> <h:selectBooleanCheckbox value="#item.selected"/> <h:outputText value="#{item.entityId}" /> </r:treeNode> <r:treeNode type="organizationNode"> <h:selectBooleanCheckbox value="#item.selected"/> <h:outputText value="#{item.organizationName}" /> </r:treeNode> <r:treeNode type="stationNode"> <h:selectBooleanCheckbox value="#item.selected"/> <h:outputText value="#{item.stationName}" /> </r:treeNode> <r:treeNode type="entityNode"> <h:selectBooleanCheckbox value="#item.selected"/> <h:outputText value="#{item.entityId}" /> </r:treeNode> </r:tree>
and the type that is referred to in each treeNode is the type returned from each TreeNode implementation in the getType method. I have also added checkboxes to each node, but haven't been able to make it work yet, that's what I'm looking at now. -
4. Re: trying to get Tree component to work.
viggo.navarsete Aug 22, 2007 3:07 PM (in response to jgreene)As you can see from my example, the entityNode is the TreeNode implementation just below the root node, and then I have an organizationNode which will be below the entityNode. Next I have a stationNode below it again, and then an entityNode again. It could look something like this:
-entityNode - organizationNode - stationNode -entityNode -entityNode -entityNode - stationNode -entityNode -entityNode - organizationNode - stationNode -entityNode
I think you have to define all you node levels in you jsp like I did. -
5. Re: trying to get Tree component to work.
jgreene Aug 22, 2007 3:33 PM (in response to jgreene)ThAnks again, Viggo. I'll do some more work and repost when I know more.
-
6. Re: trying to get Tree component to work.
viggo.navarsete Aug 22, 2007 3:35 PM (in response to jgreene)Yes please do. I will watch this forum for a couple of hours before I go to bed, so I will try to help if I can :)
-
7. Re: trying to get Tree component to work.
jgreene Aug 23, 2007 10:02 AM (in response to jgreene)Hi Viggo -
I changed the type strings to one word, but it still doesn't work. The System.out.println statements don't print anything to the tomcat console either. One thing I did notice when the page loads is that the last line in the tomcat console is: "TreeRendererBase.writeContent() 0", but I don't really know what it means.
Since my printlns aren't working, "initData" looks like it is not being called, which makes me wonder if I'm not referencing the data correctly in my jsp or something. Would it be possible for you to post the code for your root node? Maybe I could see some difference in our approaches that would provide a clue.
Thanks. -
8. Re: trying to get Tree component to work.
jgreene Aug 23, 2007 12:06 PM (in response to jgreene)Viggo - Good news!
I finally got the tree working - it was my error, and it sounds like I must have gone through some adjustments like you did.
What's left now is just cleaning up the code, styling the tree the way I want, getting the nodes to appear in the proper order, and being able to add nodes dynamically.
Thanks again for your responses and help.
Regards,
Joe -
9. Re: trying to get Tree component to work.
viggo.navarsete Aug 23, 2007 12:18 PM (in response to jgreene)think you can try two things:
1. Try with just one level, and hardcode some data in your TreeNode implementation.
2. Post some more code here:) -
10. Re: trying to get Tree component to work.
jgreene Aug 23, 2007 1:05 PM (in response to jgreene)Viggo -
I'm good now. Everything is working. Thanks again for the help. -
11. Re: trying to get Tree component to work.
viggo.navarsete Aug 23, 2007 4:31 PM (in response to jgreene)Great:)