3 Replies Latest reply on Oct 3, 2007 2:42 PM by Arthur Parisi

    Trouble with TreeNodes and ToolTips

    Arthur Parisi Newbie

      I'm trying to build a <rich:tree> with a <rich:toolTip> popup, but I'm having trouble getting the <rich:treeNode> to display properly. Currently, my JSP page looks like this:

      <rich:tree value="#{TreeBean.treeNode}" ajaxSubmitSelection="true" switchType="ajax" nodeSelectListener="#{TreeBean.processSelection}" var="item">
       <rich:treeNode>
       <h:outputText value="#{item.name}" />
       <rich:toolTip event="onclick" mode="client" layout="block" horizontalOffset="25" verticalOffset="-12">
       <h:outputText value="This is the ToolTip for #{TreeBean.nodeTitle}" />
       </rich:toolTip>
       </rich:treeNode>
      </rich:tree>


      And currently my 'TreeBean.java' resembles the demo page's version of 'SimpleTreeBean.java', except for the following section, where I statically create the tree:

      private void addNodes(String path, TreeNode node) {
       TreeNodeImpl root = new TreeNodeImpl();
       root.setData("Root");
       TreeNodeImpl branch1 = new TreeNodeImpl();
       branch1.setData("Branch 1");
       TreeNodeImpl leaf1 = new TreeNodeImpl();
       leaf1.setData("Leaf 1");
       TreeNodeImpl leaf2 = new TreeNodeImpl();
       leaf2.setData("Leaf 2");
       TreeNodeImpl branch2 = new TreeNodeImpl();
       branch2.setData("Branch 2");
       TreeNodeImpl leaf3 = new TreeNodeImpl();
       leaf3.setData("Leaf 3");
       TreeNodeImpl leaf4 = new TreeNodeImpl();
       leaf4.setData("Leaf 4");
      
       branch1.addChild("1.1.1", leaf1);
       branch1.addChild("1.1.2", leaf2);
       root.addChild("1.1", branch1);
       branch2.addChild("1.2.1", leaf3);
       branch2.addChild("1.2.2", leaf4);
       root.addChild("1.2", branch2);
       node.addChild("1", root);
      }


      I have three questions about this:
      1) Is it possible to have a <rich:toolTip> appear 'onselected' for the <rich:tree> without including separate <rich:treeNode> tags?
      2) Why does it take two clicks to activate the <rich:toolTip> box?
      3) How does #{item.name} work? I know the demo page uses this for the <h:outputText> in the <rich:treeNode>, but when I try to load that code into Eclipse, I get the warning 'item cannot be resolved'.

        • 1. Re: Trouble with TreeNodes and ToolTips
          Arthur Parisi Newbie

          Okay, so I've answered my third question. By changing my code from this:

          <rich:tree value="#{TreeBean.treeNode}" ajaxSubmitSelection="true" switchType="ajax" nodeSelectListener="#{TreeBean.processSelection}" var="item">
           <rich:treeNode>
           <h:outputText value="#{item.name}" />
          ...


          ...to this:

          <rich:tree value="#{TreeBean.treeNode}" ajaxSubmitSelection="true" switchType="ajax" nodeSelectListener="#{TreeBean.processSelection}" var="item">
           <rich:treeNode>
           <h:outputText value="#{item}" />
          ...


          ...my <rich:treeNode> is working. I figured the 'var' field of the <rich:tree> was significant, but I never thought to remove the '.name' from the EL.

          Of course, I could still use help with the other two questions.

          • 2. Re: Trouble with TreeNodes and ToolTips
            Maksim Kaszynski Apprentice

            About question 2 - I'm unable to reproduce such behavior. Whenever I click the node, I get tooltip displayed.

            about first question - could you please explain in detail what is that you need?

            • 3. Re: Trouble with TreeNodes and ToolTips
              Arthur Parisi Newbie

              Regarding question 2: I've tried this in both IE6 and IE7 on two machines. For some reason, when I click on a node, I must move my mouse and click on the node again to get the tooltip. But beyond the code I've posted, I have no other suggestions if the problem can't be duplicated.

              Regarding question 1: The hope was that I could insert a tooltip into a tree that didn't have any treenode tags in it. This would have been a workaraound for my third question. Since my tree is working now, This question is more curiosity than necessity.

              But now, I have another question that I was hoping someone could answer: is there a way to make these tooltips appear to the right of the tree at a uniform distance. Below is what I'm envisioning:

              <h:panelGrid columns="2">
               <rich:tree value="#{TreeBean.treeNode}" ajaxSubmitSelection="true" switchType="ajax" nodeSelectListener="#{TreeBean.processSelection}" var="item">
               <rich:treeNode>
               <h:outputText value="#{item.name}" />
               <rich:toolTip event="onclick" mode="client" layout="block" horizontalOffset="25" verticalOffset="-12">
               <h:outputText value="This is the ToolTip for #{TreeBean.nodeTitle}" />
               </rich:toolTip>
               </rich:treeNode>
               </rich:tree>
               <!-- Some code to make the tooltip appear to the right of the tree at a uniform distance -->
              </h:panelGrid>


              I don't want the tooltip to appear a uniform distance from the end of the outputText, but if I could display all the tooltips at once, I'd want them to appear in a left-aligned column. Is this possible, or can I create this behavior using a different RichFaces tool?