Just started out yesterday with wicket and have a question. I have a form
with some fields, at first there is a default image shown, a user can upload
an image and I want the default image to be replaced with this image. This
is what I tried:
in the form:
image_shown = new Image("show_image", getImageResource());
image_shown.setModel(new PropertyModel(search, "picture"));
add(image_shown);
getImageResource looks something like:
................
public ResourceReference getImageResource()
{
return new ResourceReference(Aclass.class, "show_image")
{
public Resource newResource()
{
final BufferedDynamicImageResource resource =
new
BufferedDynamicImageResource("jpg");
ByteArrayInputStream biss = null;
BufferedImage bim = null;
try {
biss = new ByteArrayInputStream
(search.getPicture(),0,search.getPicture().length);
JPEGImageDecoder dec =
JPEGCodec.createJPEGDecoder(biss);
bim = dec.decodeAsBufferedImage();
} catch (java.io.IOException hh) {
bim = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
drawCircle((Graphics2D)bim.getGraphics());
} catch (com.sun.image.codec.jpeg.ImageFormatException
ff) {
bim = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
drawCircle((Graphics2D)bim.getGraphics());
} catch (java.lang.NullPointerException ff) {
bim = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
drawCircle((Graphics2D)bim.getGraphics());
}
resource.setImage(bim);
return resource;
}
};
}
.................
So, if search.getPicture() does not return a byte[] (that is a jpg), a
default image will be drawn. This works.
In the form I also have:
Button uploadPicture = new Button("uploadPicture"){
protected void onSubmit() {
FileUpload upload = fileUploadField1.getFileUpload();
String mime = "";
if (upload != null)
{
byte[] stuff = upload.getBytes();
mime = upload.getContentType();
image_shown.modelChanging();
search.setPicture(stuff);
image_shown.modelChanged();
...........
So, we upload the image, set the search-object picture to the uploaded data
and update the model for the image_shown. Problem is, the image is not
updated on the screen. What have I missed? How do I update an Image? Thanks
for any help, I´m new to this framework.
Maru
--
View this message in context:
http://www.nabble.com/Update-default-image-with-form-tf4032123.html#a11454094
Sent from the Wicket - User mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user