1 Reply Latest reply on Sep 5, 2008 2:40 PM by Nick Belaevski

    tree w/context menu

    Glenn Holmer Newbie

      I have a tree with a context menu attached:

      <rich:tree binding="#{richBean.tree}"
       value="#{richBean.treeModel.rootNode}" var="person"
       switchType="ajax" ajaxSubmitSelection="true">
       <rich:treeNode id="node">
       <h:outputText id="caption" value="#{person.caption}"/>
       <rich:contextMenu id="contextMenu" event="oncontextmenu" attachTo="node" submitMode="ajax">
       <rich:menuItem value="One" id="one" ajaxSingle="true"
       actionListener="#{person.menuOneTest}">
       </rich:menuItem>
       <rich:menuItem value="Two" id="two" ajaxSingle="true"
       actionListener="#{person.menuTwoTest}">
       </rich:menuItem>
       </rich:contextMenu>
       </rich:treeNode>
      </rich:tree>
      


      but the actionListeners only fire when the node is the selected one. Is there a way to programmatically select the node when a context click is received?

        • 1. Re: tree w/context menu
          Nick Belaevski Master

          Hi,

          Here is the possible variant:

          function setSelection(e) {
          
           var elt = Event.element(e);
          
           while (elt && !elt.object) {
          
           elt = elt.parentNode;
          
           }
          
          
          
           elt.object.toggleSelection(e);
          
           Event.stop(e);
          
           }


          <rich:tree id="swingTree" switchType="client" value="#{bean.swingTreeNodes}" var="data"
          
           preserveModel="none">
          
          
          
           <rich:treeNode oncontextmenu="setSelection(event);">
          
           <h:outputText value="#{data.data}" />
          
           </rich:treeNode>
          
           </rich:tree>