7 Replies Latest reply on Apr 8, 2009 7:02 AM by njrfrens

    useMap with a4j:mediaOutput

    njrfrens

      I need to display tooltips on a chart, which is displayed as image using a4j:mediaOutput.

      I'm converting my chart object to a BufferedImage and am displaying in the JSF page using a4j:mediaOutput.

      Can somebody please tell me how to use useMap attribute here...!

      I tried in the following way, but no luck in displaying the tooltips.

      
      public void getChartImage (OutputStream out, Object data) throws Exception {
       BufferedImage pageImage = getBufferedImageFromChart(); // Converts a JFreeChartImage to BufferedImage
      
       // JFreeChart way of generating imagemap.
       ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
       ChartUtilities.writeImageMap(new PrintWriter(out), "chart", info, true); // "chart is the name of the image map"
      
       ImageIO.write(pageImage, "jpeg", out);
      }
      
      <a4j:mediaOutput
       element="img" cacheable="false" session="true" usemap="#chart"
       createContent="#{benchmarkReportsController.getChartImage}"
       mimeType="image/jpeg" />


        • 1. Re: useMap with a4j:mediaOutput
          nbelaevski

          Hi,

          How do you declare MAP object?

          • 2. Re: useMap with a4j:mediaOutput
            njrfrens

            ChartUtilities.writeImageMap(new PrintWriter(out), "chart", info, true); will write the map with id "chart".

            • 3. Re: useMap with a4j:mediaOutput
              njrfrens

              I tried in a different way also, like...

              I stored in the stored image map in a String variable
              'imageMap', in my Bean Class.

              and referred in this way... This way also didn't work for me :-(

              <a4j:mediaOutput element="img" cacheable="false" session="true" usemap="#myMap"
              createContent="#{myBean.getChartImage}"
              mimeType="image/jpeg" />


              <h:outputText escape="false" value="#{myBean.imageMap}" />



              • 4. Re: useMap with a4j:mediaOutput
                nbelaevski

                 

                "njrfrens" wrote:
                I tried in a different way also, like...

                I stored in the stored image map in a String variable
                'imageMap', in my Bean Class.

                and referred in this way... This way also didn't work for me :-(

                <a4j:mediaOutput element="img" cacheable="false" session="true" usemap="#myMap"
                createContent="#{myBean.getChartImage}"
                mimeType="image/jpeg" />

                <map id="myMap" name="myMap">
                <h:outputText escape="false" value="#{myBean.imageMap}" />
                </map>


                That's a better approach. "createContent" method is called in a separate request to render image data, so the first approach won't work.

                Have you checked generated HTML? Is MAP present there?

                • 5. Re: useMap with a4j:mediaOutput
                  njrfrens

                  something suspicious with the method in createContent...

                  I declared the imageMap as an instance variable in my Bean class.
                  and I'm setting the value for imageMap variable inside the getChartImage method of of myBean with the appropriate imageMap.

                  But the value is not set for this imageMap variable...

                  • 6. Re: useMap with a4j:mediaOutput
                    nbelaevski

                    getChartImage() is called after myBean.imageMap is output, because image tag is first rendered, then image data is requested. Probably, that's the cause? What is bean scope?

                    • 7. Re: useMap with a4j:mediaOutput
                      njrfrens

                      Hmm... seems there lies the problem...

                      I tried putting my bean in session and request scope... still no luck...

                      any advise please?