Tree, TreeNode & expand on click
Hello!
Hope it's a simple (and silly) question - I have created a page which uses a Tree with some TreeNode as navigation on a project. I have for every node an action which returns an appropriate navigation string.
Now for my problem: if a user clicks on a nodes text, that node will expand automatically. But if a user again clicks on the text, the node stays expanded - but I want it to collapse again (the node only does this if the user clicks on the icon before the text of that node).
Any hints for me?
Cheers,
Jan
[559 byte] By [
JanKesten] at [2007-11-26 11:56:02]

# 2
Hi!
Following, I have build a very simple tree with just two nodes, both have an action() handler which is returning a navigation case. After these are added both texts from the nodes turn green (indicating they are links now):
public String treeNode1_action() {
return "case1";
}
public String treeNode2_action() {
return "case2";
}
Now, if I click on the arrow of the first node the tree expands and collapses as expected.
But when the tree is collapsed and I click directly on the text/link the tree expands the subnodes for this node and selects it of course (showing an appropriate page). But when I click again on this node I'd like to have it collapsed again.
Anytime clicking on the arrow does the job, but for the user it's a bit mind-boggling if he/she can click on the text, get the page and now is able to see the subnodes - but collapsing can only be done by clicking on the arrow.
I found treeNode().toggleNode() and treeNode().setExpand() and tried to call them in the action handler - but that doesn't work, because clicking on the text expands the node before calling action() - so a toggleNode() always collapses the node.
One thing I can imagine is to use some variables to store the state of the nodes and decide on them to expand or collapse the nodes. But maybe there is a better way?! Since anywhere there must be something that expands the node...
Any hints someone?
# 3
Yup.. i see what you mean..Though i use VWP+netbeans and clicking on the tree node for collapsing and expanding does work for me..Have you tried using javascript?There is a javascript function called expandCollapse(treeNode, event)