Hi,

I have a working solution by img on the page and servlet:

In JSF page I have:

<h:graphicImage value="/svlgraph?#{GraphShowRequest.graphParam}"
width="#{GraphSession.graphWidthString}"
height="#{GraphSession.graphHeightString}"/>

In GraphShowRequest bean add some parameters for graph servlet and append unique value (currentTimeMillis) to avoid image caching in browser cache:

public String getGraphParam() {
HttpServletRequest hsrq = (HttpServletRequest)ctx.getExternalContext().getRequest(); return (repaint || "1".equals(hsrq.getParameter("print")) ? "repaint=" : "refresh=") + Long.toString(System.currentTimeMillis());
}

And servlet:

public class SvlGraph extends HttpServlet {
private static final String CONTENT_TYPE = "image/png";

public void init(ServletConfig config) throws ServletException {
super.init(config);
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
GraphSession gs = (GraphSession)request.getSession().getAttribute("GraphSession");
if (gs == null) {
System.out.println("No GraphSession to use.");
return;
}
if (request.getParameter("repaint") == null) {
gs.GraphAddData();
}
BufferedImage bi = gs.GraphCreateImage();
//BufferedImage bi = ImageIO.read(new File("/prj/test.png"));
response.setContentType(CONTENT_TYPE);
ServletOutputStream os = response.getOutputStream();
ImageIO.write(bi, "png", os);
os.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

where GraphSession object actually create image.

You must register servlet in web.xml

<servlet>
<servlet-name>SvlGraph</servlet-name>
<servlet-class>com... ...SvlGraph</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>SvlGraph</servlet-name>
<url-pattern>/svlgraph</url-pattern>
</servlet-mapping>

May be this help,
Peter


Jochen Zink wrote:
Thanks for the fast reply.

It is not possible to use tomahawk or the chartcreator comp in my environment. 
So, I hope there is a solution without using special components. I will take a 
look to the source code of chartcreator and try to find a solution.

If anyone know how it works, please let me know. :)

Thanks a lot!



-----Ursprüngliche Nachricht-----
Von: "MyFaces Discussion" <users@myfaces.apache.org>
Gesendet: 06.06.07 15:52:40
An: MyFaces Discussion <users@myfaces.apache.org>
Betreff: Re: how to create dynamic grahpics with JFreeChart and myfaces?


See JSF Chart Creator [1], it uses JFreeChart 1.0.5.

[1] http://jsf-comp.sourceforge.net/components/chartcreator/index.html <http://www.jfree.org/jfreechart>

Glauco P. Gomes

Mario Ivankovits escreveu:
Hi!
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?
Hehe - I had the same problem yesterday.

One solution is the latest tomahawk-sandbox and its graphicsImageDynamic
component.
There you can do something like:

<s:graphicsImageDynamic value="#{backingBean.chartRenderer}" where the
method signature of chartRenderer is

public ImageRenderer getChartRenderer()
{
}

To fulfill the ImageRenderer requirements is easy, just create a png/gif
byte array out of the chart and write it to the ResponseStream where
requested by the ImageRenderer Interface.
The trick is, that you have to find some way to push down informations
to the managed bean.

If you do not use MyFaces Orchestra (or Seam) which provides a
conversation scope, the easiest way is to put the backingBean into the
session scope.


Another way is to use s:graphicsImageDynamic
imageRenderer="#{backingBean.chartImageRenderer}". Then the method
signature of chartImageRenderer is
public String getChartImageRenderer() where you have to provide a FQN of
a class implementing the ImageRenderer interface.
It should work then to add f:param tags within the graphicsImageDynamic
component to pass down some informations to the renderer.
Though, I do not know much more about that way ... I am a MyFaces
Orchestra user ;-)

Ciao,
Mario




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



--

Petr Kotek
CRC Data spol. s r.o.
U krčské vodárny 26 - vývojové pracoviště
140 00 Praha 4
tel: +420 241 442 464
fax: +420 241 442 645
GSM: +420 602 339 057
www.crcdata.cz

Reply via email to