4 Replies Latest reply on Jan 14, 2009 7:51 PM by nbelaevski

    contextMenu in treeNode don't select node in 3.3.0

      Hi to all,
      I'm using a contextMenu in treeNode:

      <rich:treeNodesAdaptor id="request" nodes="#{treeModelBean.requests}" var="req">
       <rich:treeNode nodeSelectListener="#{treeModelBean.processRic}" >
       <h:outputLabel id="reqst" style="#{req.style}" value="Richiesta: #{req.accessnumber} - #{req.data}" />
       <rich:contextMenu submitMode="server" id="menu_req" attachTo="reqst" >
       <rich:menuItem rendered="#{req.canDelete}" oncomplete="Richfaces.showModalPanel('popupEditRequest');" submitMode="ajax" value="Modifica Richiesta" action="#{treeModelBean.editSavedReq}" />
       <rich:menuItem rendered="#{req.canDelete}" value="Stampa Ticket" action="#{treeModelBean.viewTicket}" />

      With version 3.2.2 when I open and select a contextMenuItem the application execute the nodeSelectListener and, after, execute the contextMenu action.
      Instead with 3.3.0 nodeSelectListener it isn't called on contextMenu action

      Something is changed? There's a workaround?

      Tanks to all.

        • 1. Re: contextMenu in treeNode don't select node in 3.3.0


          Yes, we've fixed bug in rich:contextMenu, that's why events are no more propagating to rich:tree. Check this code:

           function setSelection(e) {
           var elt = Event.element(e);
           //find component and toggle selection
           var treeItem = Tree.Item.findComponent(elt);
          if (treeItem.tree.selectionManager.activeItem != treeItem) {
           //create a copy of event for further usage
           //we'll need it to position context menu
           window.contextMenuEventCopy = Object.clone(e);
          } else {
           function showMenu(e) {
           #{rich:component('cmenu')}.show(e, {});
          <rich:tree switchType="ajax" value="#{library.data}" var="item" nodeFace="#{item.type}"
          ajaxSubmitSelection="true" nodeSelectListener="#{requestTestBean.processNodeSelection}"
          oncomplete="if (event[Richfaces.TreeSelectEvent] && event.originatingEventType == 'contextmenu') { showMenu(window.contextMenuEventCopy); }"
          <rich:treeNode oncontextmenu="setSelection(event)" type="artist" iconLeaf="/images/tree/singer.gif" icon="/images/tree/singer.gif">
          <h:outputText value="#{item.name}" />
          <rich:treeNode oncontextmenu="setSelection(event)" type="album" iconLeaf="/images/tree/disc.gif" icon="/images/tree/disc.gif">
          <h:outputText value="#{item.title}" />
          <rich:treeNode oncontextmenu="setSelection(event)" type="song" iconLeaf="/images/tree/song.gif" icon="/images/tree/song.gif">
          <h:outputText value="#{item.title}" />
           <h:panelGroup id="menu">
           <rich:contextMenu id="cmenu" attached="false" submitMode="ajax">
           <rich:menuItem value="Menu #{counter}" limitToList="true" reRender="ModalPanelDeleteElement" />

          • 2. Re: contextMenu in treeNode don't select node in 3.3.0

            Thanks nbelaevski,
            but I've got 2 problem:

            1) I cannot insert "#{rich:component..." outside jsf tags (I'm using jsf RI 1.2).

            2) According your sample, first right click do selection, and then we need another right click to show contextmenu. It's correct?

            There's no other way to propagate right click event to rich:tree?


            • 3. Re: contextMenu in treeNode don't select node in 3.3.0

              I've found a workaround:

              <script language="javascript">
               function setSelection(e) {
               var elt = Event.element(e);
               while (elt && !elt.object) {
               elt = elt.parentNode;
              <rich:menuItem onselect="setSelection(event)" ... />

              That's a trick, but, imho, should be naturally that a contextMenu on a treeNode select node automatically. Every application work so.

              May be in a future release?


              • 4. Re: contextMenu in treeNode don't select node in 3.3.0