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]
# 1
Correct me if i am wrong, but clicking on the node's text always selects the particular node. That is supposed to be the desired action. Clicking on the node's text does not expand/collapse the node.
deepsix at 2007-7-7 12:15:05 > top of Java-index,Development Tools,Java Tools...
# 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?

JanKesten at 2007-7-7 12:15:05 > top of Java-index,Development Tools,Java Tools...
# 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)
deepsix at 2007-7-7 12:15:05 > top of Java-index,Development Tools,Java Tools...
# 4
Maybe I should give VWP a try ;-) I haven't tried JavaScript so far - as I don't know how to do. When I select client side then there is some included in the page, but it isn't working either. I'll have a look for VWP...
JanKesten at 2007-7-7 12:15:05 > top of Java-index,Development Tools,Java Tools...