I am trying to implement a context menu for <p:tree> with Javascript as shown below, but the context menu would not pop up for me. I only see the standard, browser's context menu (with Reload, Back, Bookmark, etc.) upon right clicking. Could someone please point out my error? Thanks!
My tree is like this:
Code: Select all
<p:layoutUnit position="left" width="275" resizable="true" >
<h:form>
<p:tree value="#{treeBean.root}" var="node"
selection="#{treeBean.selectedNodes}"
selectionMode="checkbox"
widgetVar="conTree" id="myTree">
<p:treeNode>
<h:outputText value="#{node}" />
</p:treeNode>
</p:tree>
</h:form>
</p:layoutUnit>
Code: Select all
function onTriggerContextMenu(p_oEvent)
{
var oTarget = this.contextEventTarget;
var oCurrentNode = conTree.getNodeByElement(oTarget);
if (!oCurrentNode) {this.cancel(); }
}
var oContextMenu = new YAHOO.widget.ContextMenu(
"mytreecontextmenu",
{
trigger: "conTree",
lazyload: true,
itemdata: [
{ text: "Delete", onclick: { fn: callbackFunction } }
]
}
);
oContextMenu.subscribe("triggerContextMenu", onTriggerContextMenu);
function callbackFunction() {
alert('callback called.');
}