Accessing selected node of richfaces tree from Javascript
        Posted  
        
            by kazanaki
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by kazanaki
        
        
        
        Published on 2010-05-19T07:27:55Z
        Indexed on 
            2010/05/19
            7:30 UTC
        
        
        Read the original article
        Hit count: 435
        
Hello
This should be a very simple question. I have a richfaces tree that is rendered using JSF. When the user clicks on a node I want a javascript function to run. Nothing more nothing less. No redirects, no re-submit, no-rerender, no Ajax. Just plain old Javascript.
I have seen the onselected attribute of the tree and it indeed fires a Javascript method. But of course I want to know which node was clicked.
Here is what I have so far
<head>
<script type="text/javascript">
function documentClicked(nodeRef)
{
    alert("Node is "+nodeRef);
}
</script>
</head>
    <rich:tree switchType="client" value="#{ajaxDocumentTree.rootNode}"  
        var="document" onselected="documentClicked()" >
        <rich:treeNode   iconLeaf="../images/tree/doc.gif"
            icon="../images/tree/doc.gif">
            <h:outputText value="#{doc.friendlyName}" />
        </rich:treeNode>
But this does not work because nodeRef is undefined. I expected that the first argument of the callback would be the selected node but this is not the case.
So the question is this:
How do I fire a Javascript function with the selected node from a richfaces tree?
© Stack Overflow or respective owner