2

In my code, I'm expanding treeNode in left frame that is selected through navigation links present in right frame. It works but everytime I click the link on right frame, I have to refresh the right frame manually. I tried to reload the page from backing bean using javascript code but it's not working. Can anyone please help me to figure out why it's not getting executed.

Thanks in advance for helping me out.

Below is the code I'm using.

public void expandTreeView( TreeNode selectedNode )
{
    if ( selectedNode != null )
    {
        selectedNode.getParent().setExpanded( true );

    }
    RequestContext rc = RequestContext.getCurrentInstance();
    rc.execute("window.location.reload(true)");

}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Arzoo Mittal
  • 31
  • 1
  • 6

1 Answers1

1

You need to combine a JS Function with remoteCommand, it will look like this :

myHTML.xhtml

<p:commandLink id="commandLink" onclick="myFunction(nodeSelected)"  >
...
</p:commandLink>   

Also add a JS function

<script type="text/javascript">
   function myFunction(x) {                                
       ...                                
    }    
</script>

and finally combine it with a p:remoteCommand it allows you to call a managedBean method from your JS function

You can see Primefaces remoteCommand Example or simply look to this SO post Invoking a p:remoteCommand via a JavaScript function passing a message local to that function to another function through the “oncomplete” handler

Hope that helped you.

Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40
Yagami Light
  • 1,756
  • 4
  • 19
  • 39
  • It did not work for me. I already tried that before. I'm not selecting, expanding any node directly, that's why I think these ajax events are not working. – Arzoo Mittal Mar 20 '17 at 00:45
  • Yes, I'm using commandLink in right frame. The value attribute in command link is set in backing bean. It selects the value from tree. – Arzoo Mittal Mar 20 '17 at 19:37
  • There are a lot of commandLinks, I need to put onclick attribute manually in all of them and write myFunction(x) in all the pages this way. Is this the only way? – Arzoo Mittal Mar 21 '17 at 18:07
  • non you can put it in an include page (it's kind of a template) and use it every where reade this post [Include Example](http://stackoverflow.com/questions/42926106/primefaces-rendered-attribute-impact-on-performance/42930436#42930436) and why not upvote it ;) – Yagami Light Mar 21 '17 at 19:42