Javascript 从java脚本调用primefaces上下文菜单

Javascript 从java脚本调用primefaces上下文菜单,javascript,xhtml,contextmenu,Javascript,Xhtml,Contextmenu,我的网页上有一个svg。右键单击时,元素应显示一个上下文菜单,其中包含从数据库获取的数据。 元素的编写方式使右键单击事件触发页面上的js函数。我需要从java脚本中调用上下文菜单。谁能帮我一下吗。我被这个问题困扰了将近3天。 要素: <rect/><text>L</text></g><g id="118" onmousedown="RightClickExecute(event,118)"> XHTML: <p:contextM

我的网页上有一个svg。右键单击时,元素应显示一个上下文菜单,其中包含从数据库获取的数据。 元素的编写方式使右键单击事件触发页面上的js函数。我需要从java脚本中调用上下文菜单。谁能帮我一下吗。我被这个问题困扰了将近3天。 要素:

<rect/><text>L</text></g><g id="118" onmousedown="RightClickExecute(event,118)">
XHTML:

<p:contextMenu id="contextMenuId" for="svgContainerPanel"
                widgetVar="contextMenuVar" rendered="#{myBean.objectType=='Entity' ? true : false}">
                <p:menuitem id="contextMenuItemId" ></p:menuitem>
</p:contextMenu>

<p:contextMenu event="click" id="contextMenu2Id" for="contextMenuId"
                widgetVar="contextMenu2Var" model="#{my.model}" >

                </p:contextMenu>

<p:commandButton id="RightAction" style="visibility:hidden"
                action="#{myBean.populateMenu}" ajax="true"
                type="submit" oncomplete="showContextMenu()"
                update="contextMenuId,contextMenu2Id">
            </p:commandButton>

<h:inputHidden id="selectedEntityid"
                value="#{myBean.selectedEntityId}">
            </h:inputHidden>
<h:inputHidden id="selectedObjectType"
                value="#{myBean.objectType}">
            </h:inputHidden>

Primefaces的contextMenu没有获取该选项,因此您可以使用jquery来实现。如果要显示contextMenu,必须将contextMenu的位置更改为鼠标的位置(默认情况下,页面加载contextMenu,但它有css显示:无,因此需要更改css)。Primefaces的contextMenu具有widgetvar属性以在客户端中使用(它具有方法show以显示它)

Primefaces的contextMenu
具有要在客户端中使用的
widgetvar
属性(它具有显示它的方法)

例如,当鼠标悬停在一个id为
rongnk
、我有一个表单(id:form)、一个contextmenu(id:xxx)的组件上时,显示contextmenu


//
<p:contextMenu id="contextMenuId" for="svgContainerPanel"
                widgetVar="contextMenuVar" rendered="#{myBean.objectType=='Entity' ? true : false}">
                <p:menuitem id="contextMenuItemId" ></p:menuitem>
</p:contextMenu>

<p:contextMenu event="click" id="contextMenu2Id" for="contextMenuId"
                widgetVar="contextMenu2Var" model="#{my.model}" >

                </p:contextMenu>

<p:commandButton id="RightAction" style="visibility:hidden"
                action="#{myBean.populateMenu}" ajax="true"
                type="submit" oncomplete="showContextMenu()"
                update="contextMenuId,contextMenu2Id">
            </p:commandButton>

<h:inputHidden id="selectedEntityid"
                value="#{myBean.selectedEntityId}">
            </h:inputHidden>
<h:inputHidden id="selectedObjectType"
                value="#{myBean.objectType}">
            </h:inputHidden>
            <script type="text/javascript">
                //<![CDATA[
                $(document).on('mouseover', '#form\\:rongnk', function(e) {
                    $(PrimeFaces.escapeClientId('form:xxx')).css({
                        top: e.pageY+'px',
                        left: e.pageX+'px'                        
                    }).show();
                });                
                //]]>
            </script>