3

i have a svg on my webpage. The elements when right clicked on should display a context menu with data fetched from the database. The elements are written in such a way that the right click event triggers a js function on the page. And i need to invoke the context menu from the java script. Can someone please help me with this. I have been stuck with this issue for almost 3 days. The element :

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

java script :

function RightClickExecute(event, id) {
   if (event.button == 2) {document.getElementById("myForm:selectedEntityid").value = id;
      document.getElementById("myForm:selectedObjectType").value = 'Entity';
      document.getElementById("myForm:RightAction").click();
   }
}
function showContextMenu(){                                  
   document.getElementById("myForm:contextMenuItemId").click();
 }

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>
4

1 に答える 1