The p:contextMenu
has a beforeShow
attribute that can be used to fire a client-side javascript function (as can be read in the documentation).
It also has a targetFilter, to only fire on certain elements within the 'for'. If you give your form an explicit id (e.g. myForm), you can have it fire only on the menu item links:
<p:contextMenu for="menu" targetFilter="#myForm\\:menu .ui-menuitem-link" beforeShow="...">
You can e.g. do a console.log(this)
or a console.log(event)
and from those check what you need and have access to, it is a lot.
'this' in the context of the contextMenu has a jqTarget property that will get you the html component the contextMenu was fired for (the menu), but you can also use the event object which has a target that is the specific menu item.
<p:contextMenu for="menu" targetFilter="#myForm\\:menu .ui-menuitem-link" beforeShow="console.log(this); console.log(event)">
Will give you an output like
Object { _super: undefined, cfg: Object, id: "myForm:j_idt118", jqId: "#myForm\:j_idt118", jq: Object, widgetVar: "widget_myForm_j_idt118", keyboardTarget: Object, links: Object, rootLinks: Object, jqTargetId: "#myForm\:menu", 1 meer… } panelMenu.xhtml:655:174
Object { originalEvent: contextmenu, type: "contextmenu", isDefaultPrevented: returnFalse(), target: <a.ui-menuitem-link.ui-corner-all.ui-state-hover>, currentTarget: <div#myForm:menu.ui-panelmenu.ui-widget>, relatedTarget: null, timeStamp: 103942249, jQuery31004030775514688282: true, delegateTarget: HTMLDocument → panelMenu.xhtml, handleObj: Object, 1 meer… }
So you do need javascript to get to the real value of what you need, you just do not need custom jquery.
Since I do not know where your hidden field is, I cannot incorporate that in my answer. Sorry