0 Replies Latest reply on Apr 28, 2012 4:11 AM by Karsten Wutzke

    rich:contextMenu not working as expected

    Karsten Wutzke Expert

      Hello,

       

      I am trying out rich:contextMenu, but I can't get it to show up on tree nodes set as target. Here's the code:

       

      {code:xml}<ui:composition xmlns="http://www.w3.org/1999/xhtml"

                      xmlns:f="http://java.sun.com/jsf/core"           

                      xmlns:h="http://java.sun.com/jsf/html"

                      xmlns:ui="http://java.sun.com/jsf/facelets"

                      xmlns:a4j="http://richfaces.org/a4j"

                      xmlns:rich="http://richfaces.org/rich">

        <rich:tree toggleType="client"

                   value="#{rootNode}"

                   var="treeNode"

                   nodeType="#{treeNode.emitCode}"

                   id="#{treeId}"

                   style="margin: 5px auto;width:100">

       

          <rich:treeNode type="root"

                         id="rootnode"

                         expanded="#{true}">

            <a4j:outputPanel layout="block">

              <rich:dropTarget acceptedTypes="chapter-#{coDndSuffix}"

                              dropValue="#{treeNode}"

                              dropListener="#{homeBean.processDrop}"                       

                              render="#{treeId}" />

              <h:panelGrid columns="2">

                <h:outputText value="#{name}" />

       

                <rich:popupPanel modal="true" autosized="true"

                                        resizeable="false"

                                        onmaskclick="#{rich:component('node-add-popup-root')}.hide(); return false;"

                                        id="node-add-popup-root">

                  <f:facet name="header">

                    <h:outputText value="Add Chapter" />

                  </f:facet>

                  <f:facet name="controls">X</f:facet>

                  <h:inputText id="chapterNameRoot" value="#{treeNode.nodeNameRoot}" size="80"></h:inputText>

                  <p>Add chapter?</p>

                  <h:panelGrid columns="2" style="margin: 0 auto;">

                    <h:commandButton value="OK" action="#{homeBean.addChapterRoot(treeNode,treeNode.nodeNameRoot)}"

                              onclick="#{rich:component('node-add-popup-root')}.hide(); return true;">

                    </h:commandButton>

                    <h:commandButton value="Canel" onclick="#{rich:component('node-add-popup-root')}.hide(); return false;" />

                  </h:panelGrid>

                </rich:popupPanel>

              </h:panelGrid>

            </a4j:outputPanel>

          </rich:treeNode>{code}

          ... some more rich:treeNodes

       

      {code:xml}    <rich:contextMenu target="rootnode" mode="ajax">

            <rich:menuItem label="Add chapter..." render="node-add-popup-root" oncomplete="#{rich:component('node-add-popup-root')}.show();"

                           mode="ajax" icon="/resources/images/icons/add.png"/>

          </rich:contextMenu>{code}

      I pretty much followed the showcase demo at http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=contextMenu&sample=tree&skin=wine

       

      First of all: what's the render="popupContent" for in the example?

       

      As you can see from my code target="..." is the rootnode ID. I want to achieve different context menus per node type. How can I attach it to root nodes only? Currently it seems to be displayed anywhere on the tree form.

       

      What am I doing wrong?

       

      Karsten