4 Replies Latest reply on Dec 1, 2014 4:13 AM by sesharao_n

    Tooltip programmatically does not show!

    ealonso04

      Hi guys!

       

      I have a really weird problem trying to use a ToolTip created programmatically inside a rich:dataTable column. I'm using Richfaces 4.2.2 Final.

       

      This is the java code snippet where I create the tooltip:

       

      UITooltip toolTip = new UITooltip();
      toolTip.setValueExpression("value", uEL.createValueExpression("#{dynamicItem.toolTip}", String.class));
      
      column.getChildren().add(toolTip);
      column.getChildren().add(output);
      

       

      dynamicItem.toolTip has the String I want the tooltip show. I don't know if this is the right way to create a tooltip programmatically. It is a natural way for me.

       

      So when I run my application and check the list of items generated, the tooltip does not show and in the firebug console I have an error telling me that RichFaces.ui.Tooltip is not a constructor. As follows:

      tooltip_error_browser_01.PNG

      I have no idea why is this happening.

       

      I have saw in some posts people using the HtmlToolTip class to create a tooltip programmatically, but I can't find that class in my application. So I guess I'm missing some JAR which has that class. Could you guys tell me which JAR I have to use in order to can instantiate the HtmlToolTip class?

      These are some JARs I'm using right now:

       

      richfaces-components-api-4.2.2.Final.jar

      richfaces-components-ui-4.2.2.Final.jar

      javax.faces-2.1.7.jar

       

      Well, I hope somebody can help me out with this. I would appreciete a lot.

      Thanks in advance!

       

      Regards!

        • 1. Re: Tooltip programmatically does not show!
          lfryc

          Hey Ernesto, you are hitting issue where programatically added components does not load their resources.

           

          You will need to place tooltip on initially rendered view - you can make it rendered=false, but it needs to be there.

           

          Update: ouch, or better approach: you can load all the resources in one bundle, see:

          http://rik-ansikter.blogspot.cz/2012/02/optimizing-resource-loading-with.html

          1 of 1 people found this helpful
          • 2. Re: Tooltip programmatically does not show!
            ealonso04

            Hi Lukas!

             

            Thanks for answering. I don't understand how creating a Tooltip programmatically, has to do something with loading resources. For me, it's just a matter of create a component, set it a value and then finally attach it to the column.

            The data I need to put in the Tooltip is available just at runtime. Besides, I need to create the Tooltip at the moment I'm creating the column of the datatable in order to attach the tooltip to it.

             

            I read the post you gave me and added the context-param in web.xml. I suppose I missed to pack the several resources I have like css, javascript and the like, because I had some errors "NetworkError: 404 Not Found" as you can see in the following image:

            tooltip_error_browser_02.PNG

            But at the end I'm still getting the same error regarding the Tooltip (as you can see), so I can say, even though I have had the resources packages, the Tooltip is still not working.

             

            Can you explain me in detail how could I place the tooltip "on initially rendered view" as you said before? I can't understand how's the relation between "placing some component in a render view" and "creating it programmatically". In the case when we use a Binding I can understand that relation, but not now.

             

            Thanks in advance for your help!

            • 3. Re: Tooltip programmatically does not show!
              ealonso04

              Hi Lukas!

               

              I did what you told me and added a few lines in my web.xml taken from https://community.jboss.org/wiki/Troubleshooting-ResourceOptimization#comment-10489 so I have my tooltips working fine right now.

              These are the lines I added:

               

              <servlet>
                  <servlet-name>Resource Servlet</servlet-name>
                  <servlet-class>org.richfaces.webapp.ResourceServlet</servlet-class>
                  <load-on-startup>1</load-on-startup>
              </servlet>
              <servlet-mapping>
                  <servlet-name>Resource Servlet</servlet-name>
                  <url-pattern>/org.richfaces.resources/*</url-pattern>
              </servlet-mapping>

               

              But I have the error I put in the comments section of the Troubleshooting - Resource Optimization as you saw before.

               

              I'm gonna put it in another discussion. Thanks!

              • 4. Re: Tooltip programmatically does not show!
                sesharao_n

                By setting id to the component through programmatically, I am able to resolve this.

                 

                Below you can find some sample code,


                private UIComponent createLocationContainer(IExecutionPlan IEplan) {

                  UIComponent locationContainer = this.htmlGenerator.createContainer("locationContainer");

                  locationContainer.setId("v" + Calendar.getInstance().getTimeInMillis() + new Random().nextInt());  //Setting Unique Id

                  serviceVisitedNodes(locationContainer);

                  UIComponent nodeNameContainer = this.htmlGenerator.createContainer("nodeNameContainer");

                  nodeNameContainer.setId("v" + Calendar.getInstance().getTimeInMillis() + new Random().nextInt()); //Setting Unique Id

                 

                  /** Adds a popup with terminalservices * */
                  UITooltip terminalServicesTooltip = new UITooltip();

                  terminalServicesTooltip.setFollowMouse(false);

                  terminalServicesTooltip.setHorizontalOffset(0);

                  terminalServicesTooltip.setVerticalOffset(0);


                  terminalServicesTooltip.setStyleClass("infoPopup bigPopup");

                  terminalServicesTooltip.getChildren().add(

                   this.htmlGenerator.createTextLine("Terminal Services in " + location.getName(), "heading"));


                   terminalServicesTooltip.getChildren().add(this.createTerminalServiceContainer(IEplan));

                  nodeNameContainer.getChildren().add(terminalServicesTooltip);

                   //Tool tip should also be popped up when hovering the globe itself
                   locationContainer.getChildren().add(terminalServicesTooltip);

                 

                   nodeNameContainer.getChildren().add(this.htmlGenerator.createTextLine(this.location.getName(), "nodeHeading"));

                 

                  locationContainer.getChildren().add(nodeNameContainer);

                   return locationContainer;

                }