0

Following the example here I have tried to override the show() mehtod of a Primefaces context menu.

Here my code:

       <p:tree value="#{myTreeBean.mainTreeRoot}" id="myTree>
                       <p:ajax event="contextMenu" listener="#{myTreeBean.onRightClickSelectListener}" oncomplete="PF('serverTreeMenuVar').show()"/>
[...]
        </p:tree>

    <p:contextMenu widgetVar="myTreeMenuVar" for="myTree" id="myTreeMenu" model="#{myBean.contextMenuModel}"></p:contextMenu>

     <script>

                    $( function() {
                        PF('myTreeMenuVar').show = function(e) {
                    console.log('my function');
                    // call the generic implementation:
                    PrimeFaces.widget.ContextMenu.prototype.show.call(this,e);
                }
                    });


    </script>

Unfortunately I get the error:

Uncaught TypeError: Cannot read property 'pageX' of undefined


I'm using PF 7.0

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Neo
  • 1,337
  • 4
  • 21
  • 50

1 Answers1

0

Override was ok, the problem was caused by the following line:

  <p:ajax event="contextMenu" listener="#{myTreeBean.onRightClickSelectListener}" oncomplete="PF('serverTreeMenuVar').show()"/>

in particular from

oncomplete="PF('serverTreeMenuVar').show()"
Neo
  • 1,337
  • 4
  • 21
  • 50
  • 1
    So if you'd have started creating a [mcve] by removing a lot from your code including this line, you'd have immediately seen that it was not related to the overriding... That is what [mcve]'s are for... Narrow things down, rooot cause analysis – Kukeltje Aug 09 '19 at 11:14