jsf - Selected tree node not set when context menu action is invoked -


i'm creating primefaces (5.3) tree context menu. selected nodes should stored in #{mybean.selectednode}. when select node using left mouse button correct node set. but, when try run action on node context menu, without selecting first, correct node isn't set (the setter in bean not called).

i'm following example in primefaces showcase, , suppose i've got lined up. doing wrong?

as can see, in primefaces showcase able right click node, click "view", , growl display correct node.

bean

i don't think bean code relevant (it viewscoped , there private treenode selectednode getter , setter).

here interesting bits though:

public void onnodeselect(nodeselectevent event) {     mytreenode mytreenode = (mytreenode) event.gettreenode();     mycontroller.setselected(mytreenode.getentity()); }  public void addchild(string name) {     mytreenode mytreenode = (mytreenode) selectednode;     mytreenode childnode = mytreenode.addchild(name);     mycontroller.setselected(childnode.getentity());     mycontroller.insert(); } 

xhtml

<h:form id="mainform">     <p:tree value="#{mybean.root}" var="node"             id="mytree" dynamic="true"             selectionmode="single" selection="#{mybean.selectednode}">         <p:treenode expandedicon="ui-icon-folder-open" collapsedicon="ui-icon-folder-collapsed"                     type="mytype">             <h:outputtext value="#{node}"/>         </p:treenode>         <p:ajax event="select" listener="#{mybean.onnodeselect}" />     </p:tree>      <p:contextmenu for="mytree">         <p:menuitem action="#{mybean.addchild('new')}"                     value="add"                     process="@this"                     update=":mainform:mytree"/>     </p:contextmenu> </h:form> 

hy,
bug in primefaces.
can fixed issue youself. neccessary add verification in primefaces js file mouse button has been pressed. can override file primefaces.js in project, find first call function selectnode(d) , add follow checking:

if (e.which == 1) {     this.selectnode(d)     this.cursornode = d; } 

this part of code can find function nodeclick: function (e, a) called:

nodeclick: function (e, a) {     primefaces.clearselection();     if ($(e.target).is(":not(.ui-tree-toggler)")) {         var d = a.parent();         if (this.cfg.onnodeclick) {             this.cfg.onnodeclick.call(this, d)         }         if (a.hasclass("ui-tree-selectable") && this.cfg.selectionmode) {             var c = this.isnodeselected(d), f = e.metakey || e.ctrlkey, b = e.shiftkey;             if (this.ischeckboxselection()) {                 this.togglecheckboxnode(d)             } else {                 if (c && f) {                     this.unselectnode(d)                 } else {                     if (this.issingleselection() || (this.ismultipleselection() && !f)) {                         this.unselectallnodes()                     }                     if (this.ismultipleselection && b) {                     } else {                         if (e.which == 1) {                              this.selectnode(d);                              this.cursornode = d;                         }                     }                 }             }         }     } } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -