I want to create a component which can be used like:
<mc:chart data="#{bean.data}" width="200" height="300" />
where #{bean.data}
returns a collection of some objects or chart model object or something else what can be represented as a chart (to put it simple, let's assume it returns a collection of integers).
I want this component to generate html like this:
<img src="someimg123.png" width="200" height="300"/>
The problem is that I have some method which can receive data and return image, like:
public RenderedImage getChartImage (Collection<Integer> data) { ... }
and I also have a component for drawing dynamic image:
<o:dynamicImage width="200" height="300" data="#{bean.readyChartImage}/>
This component generates html just as I need but it's parameter is array of bytes or RenderedImage i.e. it needs method in bean
like this:
public RenderedImage getReadyChartImage () { ... }
So, one approach is to use propertyChangedListener
on submit to set data (Collection<Integer>
) for drawing chart and then use <o:dynamicImage />
component. But I'd like to create my own component which receives data and draws chart.
I'm using facelets but it's not so important indeed. Any ideas how to create the desired component?
P.S. One solution I was thinking about is not to use <o:dynamicImage/>
and use some servlet to stream image. But I don't know how to implement that correctly and how to tie jsf component with servlet and how to save already built chart images (generating new same image for each request can cause performance problems imho) and so on..