Hello,

I want to show a BufferedImage on a JSF-generated page. In my case, this Image 
is generated by the JFreeChart[1] library. Now my question:
What must I do, that I can show this image as a graphic on a JSF Page?

I try to use normal <h:graphicImage > tag with a url attribute which points to 
another jsf site. This jsf site as the content/type "image/jpeg" and calls a 
BackingBean which generates a BufferedImage Objekt. This Object is writen to 
the outputstream of the response Object. It works nearly fine. The Image is 
correctly generated and shown in the Webbrowser. But on the servers console is 
a exception thrown:

15:09:10,184 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for 
this response

I hope you understand my bad english!


Here is the part of the JSF-Page, which shows the Image:
        <h:graphicImage 
                        alt="testDiagramm"
                        width="800"
                        height="600"
                        url="createChart.jsf"/>



And the createChart.jsf:
<%@ page contentType="image/jpeg" %>
...
<% 

         FacesContext context = FacesContext.getCurrentInstance();
         
         Application app = context.getApplication();
    BufferedImage image = (BufferedImage) 
app.createMethodBinding("#{chartCreator.generateTestChart}", 
null).invoke(context, null);
         
    
         
    ServletOutputStream sos = response.getOutputStream(); 
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( sos ); 
    encoder.encode( image ); 
 %>

Thanks a lot!

[1] http://www.jfree.org/jfreechart/
_______________________________________________________________
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192

Reply via email to