This content has been marked as final.
Show 4 replies
-
1. Re: Select Tree Node with JavaScrip
nbelaevski Jan 30, 2009 6:54 AM (in response to zjda)Try this: [
code] function setSelection(e) {
var elt = Event.element(e);
//find component and toggle selection
var treeItem = Tree.Item.findComponent(elt);
if (treeItem.tree.selectionManager.activeItem != treeItem) {
treeItem.toggleSelection(e);
}
} -
2. Re: Select Tree Node with JavaScrip
nbelaevski Jan 30, 2009 6:55 AM (in response to zjda)Sorry.
Try this:function setSelection(e) { var elt = Event.element(e); //find component and toggle selection var treeItem = Tree.Item.findComponent(elt); if (treeItem.tree.selectionManager.activeItem != treeItem) { treeItem.toggleSelection(e); } }
"e" argument stands for event object.
It's not possible to check function keys out of the box for D'n'D, I think you can code that manually. -
3. Re: Select Tree Node with JavaScrip
zjda Jan 31, 2009 6:16 PM (in response to zjda)Hi Nick, Thank you for your answer and sample code. However, I have a couple of problems with the javascript. First, it is difficult to get node object. I tried the different D'n'D events, but they all gave me the receiver node. Furthermore, when the node is highlighted with a rectangle by using toggleSelection, it does not fire selection event.
Now I figure out that I can do it in the backbean drop listener:ListRowKey<Long> targetRowKey = (ListRowKey<Long>) tree.getTreeNodeRowKey(target); ListRowKey<Long> rowKey = new ListRowKey<Long>(targetRowKey, source.getData().getObjectID()); treeState.setSelected(rowKey);
Where I use objectID as the rowkey.
Again, your reply is appreciated.
-ZJ -
4. Re: Select Tree Node with JavaScrip
nbelaevski Feb 1, 2009 8:34 AM (in response to zjda)Ok, so here is how to get drag source and drop receiver on client side:
ondragstart="window.status = ('drag:' + window.drag.source)" ondrop="window.status = ('drag:' + window.drag.source)+('drop:' + this)"
For the case of tree component both variables point to an instance of Javascript class Tree.Item and you can invoke toggleSelection(event) on any of them.
For the case of server-side there's a special adviseNodeSelected attribute that should point to a method receiving UITree and returning java.lang.Boolean. See Javadoc of org.richfaces.component.state.TreeStateAdvisor class for more information about this method.