I have a Wicket page which will dynamically display an image. Let's say the image is the current date/time.
In HTML, I would have something like
<img src="[dynamically generated]"/>
Assume I have a utility method which returns to me a byte[] of the current image.
public byte[] getCurrImage();
How do I implement this dynamic resource in Wicket (HTML/Java)? I can't mount a shared resource because the image will keep changing all the time. Do I need to save the image somewhere?
Thanks
Checkout JFreeChart and wicket example.
There you will see an example of a class that derives from Image
and it gets a byte[]
to dynamically create an image like you asked.
This the way I've done it (wicket 1.5). First, your markup:
<img wicket:id="mmFigure" />
And then the code:
add(new NonCachingImage("mmFigure", new AbstractReadOnlyModel<DynamicImageResource>(){
@Override public DynamicImageResource getObject() {
DynamicImageResource dir = new DynamicImageResource() {
@Override protected byte[] getImageData(Attributes attributes) {
return getCurrImage();
}
};
dir.setFormat("image/png");
return dir;
}
}));