2 Replies Latest reply on Sep 7, 2011 4:38 AM by Nicolas C.

    HtmlTooltip programmatically is not displayed

    Nicolas C. Newbie

      Hello,

       

      I'm trying to add an HtmlToolTip programmatically to an HtmlOutputText, but the tooltip is not displayed.

       

      I've the following piece of code in my backing bean :

       

      private HtmlOutputText htmlOutputText;
      private HtmlToolTip htmlTooltip;
      
      public HtmlOutputText getHtmlOutputText() {
          htmlOutputText = new HtmlOutputText();
      
          htmlOutputText.setValue("myHtmlOutputText");
          htmlOutputText.getChildren().clear();
          htmlOutputText.getChildren().add(getHtmlTooltip());
      
          return this.htmlOutputText;
      }
      
      public HtmlToolTip getHtmlTooltip() {
          htmlTooltip = new HtmlToolTip();
      
          htmlTooltip.setValue("blabla");
          htmlTooltip.setLayout("block");
          htmlTooltip.setStyle("tooltip");
          htmlTooltip.setMode("ajax");
      
          return this.htmlTooltip;
      }   
      

       

      And this piece of code in my .jsp :

       

      <h:outputText binding="#{resultPrestationBean.htmlOutputText}" />
      

       

      When I move the mouse over the text of the HtmlOutputText, nothing happens. There is no javascript error either.

       

       

      However, when I do it this way, it works :

       

       

      <h:outputText value="myHtmlOutputText">
           <rich:toolTip binding="#{resultPrestationBean.htmlTooltip}" />
      </h:outputText>
      

        

       

       

      I'm using the following libraries : MyFaces 1.1.5, Tomahawk 1.1.9, jQuery 1.5.2, RichFaces 3.1.6.

       

      I tried with an HtmlAjaxOutputPanel too but it didn't work.

       

      What am I doing wrong ?

       

      Thank you,

      Nicolas

        • 1. Re: HtmlTooltip programmatically is not displayed
          Nicolas C. Newbie

          Hello everybody,

           

          No idea ?

          Couldn't someone provide me with an example that is working ?

           

           

          Thank you in advance.

          Nicolas.

          • 2. Re: HtmlTooltip programmatically is not displayed
            Nicolas C. Newbie

            Hello everybody,

             

            Some news.

             

            I made a little mistake in the last piece of code I gave : I forgot to give an ID to the h:outputText. If you don't give an ID, tooltip won't be displayed (that's not really intuitive).

             

            So, this is correct (and the cleanest way to do it) :

             

            <h:outputText value="myHtmlOutputText" id="outputTextId">
                 <rich:toolTip binding="#{resultPrestationBean.htmlTooltip}" />
            </h:outputText>
            

             

             

            For the first piece of code, I found a way to make it work the way I want. Not sure it is the best way to do it and if it's useful as we can use the code above, but maybe it can be useful for someone ?

             

            public HtmlOutputText getHtmlOutputText() {
                htmlOutputText = new HtmlOutputText();
                htmlOutputText.setId("myId");
                htmlOutputText.setValue("myHtmlOutputText with tooltip");
                htmlOutputText.getChildren().add(getHtmlTooltip());
            
                try {
                    htmlOutputText.encodeChildren(getFacesContext());
                    htmlOutputText.encodeEnd(getFacesContext());
                } catch (IOException e) {
                    e.printStackTrace();
                } 
            
                // Set value to null otherwise the text value that you set before will be displayed twice.
                htmlOutputText.setValue(null);
                return this.htmlOutputText;
            }
            

             

            Nicolas.