5 Replies Latest reply on Oct 16, 2008 10:57 AM by Jeronimo Azevedo

    Passing tree info

    Jeronimo Azevedo Newbie

      Hi,

      I have tree and on the last leaf I have a context menu. I need to pass the node value to my Bean so that I can used in a database query. I have tried actionParameter but no success

      <rich:treeNodesAdaptor var="dslam" nodes="#{switch.dslams}">
       <rich:treeNode id="dslam">
       <h:commandLink id="caption" value="#{dslam.name}" />
       <rich:contextMenu id ="contextmenu" event="oncontextmenu" attachTo="dslam" submitMode="ajax">
       <rich:menuItem submitMode="ajax" value="Audit" ajaxSingle="true" action="#{simpleDslamTree.audit}" id="audit">
       <a4j:actionparam value="{dslam}" assignTo="#{simpleDslamTree.selectedDslam}" />
       </rich:menuItem>
       <rich:menuItem value="Delete" onclick="" id="delete"/>
       </rich:contextMenu>
       </rich:treeNode>
      </rich:treeNodesAdaptor>
      
      


      My SimpleDslamTree bean code
      @Name("simpleDslamTree")
      @Scope(ScopeType.CONVERSATION)
      public class SimpleDslamTree {
      
       @In
       private EntityManager entityManager;
      
       @Logger
       private Log log;
      
       @DataModel
       private List<Central> rootNode = null;
      
       private Dslam dslam;
      
       private void loadTree() {
       rootNode = entityManager.createQuery("select c from Central c order by c.id").getResultList();
       }
      
       public List<Central> getTreeNode() {
      
       if (rootNode == null) {
       loadTree();
       }
       return rootNode;
       }
      
       public void setTreeNode(List<Central> rootNode) {
       this.rootNode = rootNode;
       }
      
       public void audit(ActionEvent event) {
       UIMenuItem tree = (UIMenuItem)event.getComponent();
      
       log.info("Node: "+event.getComponent());
      
       log.info("ActionEvent Running Audit on ...");
       }
      
       public void audit() {
       log.info("Get Running Audit on ...");
       log.info("Dslam: "+ dslam);
       }
      
       public void process(NodeSelectedEvent event) {
       log.info(event.getComponent());
       }
      
       public Dslam getSelectedDslam() {
       log.info("GET Dslam: "+ dslam);
       return dslam;
       }
      
       public void SelectedDslam(Dslam dslam) {
       log.info("SET Dslam: "+ dslam);
       this.dslam = dslam;
       }
      
      }
      


      Any idea how I could do it?

      Thanks

      Jeornimo

        • 1. Re: Passing tree info
          César Pérez Newbie

          I have show the menu using a component control:

          <rich:componentControl for="menu:jarMenu" event="oncontextmenu" operation="show">
           <f:param name="projectId" value="#{project.id}"/>
           <f:param name="jarName" value="#{jar.name}"/>
           </rich:componentControl>


          and in the menu
          <rich:contextMenu id="jarMenu" attached="false" >
           <rich:menuItem value="#{repo.action_add_package}" oncomplete="#{rich:component('addPackagePanel')}.show()"
           submitMode="ajax" ajaxSingle="true">
           <a4j:actionparam value="{projectId}" assignTo="#{projectLibraryTrackingBean.projectId}" />
           <a4j:actionparam value="{jarName}" assignTo="#{projectLibraryTrackingBean.jarName}" />
           </rich:menuItem>
          ....


          and it works

          • 2. Re: Passing tree info
            Nick Belaevski Master

            As contetx menu is inside tree and output for each tree node you should use:

            <a4j:actionparam value="#{dslam}" assignTo="#{simpleDslamTree.selectedDslam}" />
            instead.

            • 3. Re: Passing tree info
              Jeronimo Azevedo Newbie

               

              "nbelaevski" wrote:
              As contetx menu is inside tree and output for each tree node you should use:
              <a4j:actionparam value="#{dslam}" assignTo="#{simpleDslamTree.selectedDslam}" />
              instead.


              Hi,

              I tried it out but nothing is happening, the value is not passed. I don't understand why. Any other suggestion

              Thanks,

              Jeornimo

              • 4. Re: Passing tree info
                Anders Norgaard Newbie

                Hi,

                I tried the same, and used a hack.

                
                <rich:treeNode type="leaf" id="cpeleaf">
                 <rich:contextMenu event="oncontextmenu" attached="true" id="leafcm">
                 <rich:menuItem value="Edit value" action="#{cpemanager.editVal(item)}" submitMode="ajax" id="contextmenueditval" />
                 </rich:contextMenu>
                </rich:treeNode>
                


                by having the "item"s toString method return an ID I could look up the item.

                Best
                Anders

                • 5. Re: Passing tree info
                  Jeronimo Azevedo Newbie

                   

                  "biehl" wrote:
                  Hi,

                  I tried the same, and used a hack.

                  
                  <rich:treeNode type="leaf" id="cpeleaf">
                   <rich:contextMenu event="oncontextmenu" attached="true" id="leafcm">
                   <rich:menuItem value="Edit value" action="#{cpemanager.editVal(item)}" submitMode="ajax" id="contextmenueditval" />
                   </rich:contextMenu>
                  </rich:treeNode>
                  


                  by having the "item"s toString method return an ID I could look up the item.

                  Best
                  Anders



                  Thanks Anders it works :-) I can passe the id of my dslam without having to change my toString method

                  Cheers,

                  Jeronimo