Access selected node tree richfaces from Javascript

This should be a very simple question. I have a richfaces tree that is created using JSF. When the user clicks on node, I want to run a javascript function. No more, no less. No redirects, no resubmission, no retry, no Ajax. Just old javascript.

I saw the onselected attribute of the tree, and it really runs the Javascript method. But, of course, I want to know what node clicked on.

That's what i still have

<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="#{document.friendlyName}" />

        </rich:treeNode>

But this does not work, because nodeRef is undefined. I expected node to be the first argument of the callback, but this is not the case.

So the question is:

How do I run a Javascript function with the selected node from the interface tree?

+3
2

, javascript node .

<head>
<script type="text/javascript">
function documentClicked(nodeRef)
{
    alert("Node id is "+nodeRef);
}

</script>
</head>


    <rich:tree switchType="client" value="#{ajaxDocumentTree.rootNode}"  
        var="document" >

        <rich:treeNode onclick="documentClicked('#{document.id}')">

            <h:outputText value="#{document.friendlyName}" />

        </rich:treeNode>
+4

JSF, ( ) node, JavaScript?

:

function documentClicked()
{
    alert("Node is " + this);
}

a > : . , JSF

<rich:tree switchType="client" value="#{ajaxDocumentTree.rootNode}"  
        var="document" onselected="documentClicked(this)" >
0

Source: https://habr.com/ru/post/1746134/


All Articles