-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi guys, i got problem with showing image, which i get from database.
This is how I define picture attribute in model class:
@Lob
@Column (name = "picture")
private byte[] picture;
My question is how can i get this picture and show it in a listcell?
I tried this 2 ways:
1.
<listcell>
<image content="@load(each.picture)"/>
</listcell>
2.
<listcell>
<image src="@load(each.picture)"/>
</listcell>
But none of this was working.
Thx for help.
<image content="@load(each.picture) @converter('be.chillworld.web.vm.util.ImageToZkImageConverter')" />
ImageToZkImageConverter.class :
package be.chillworld.web.vm.util;
import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.zkoss.bind.BindContext;
import org.zkoss.bind.Converter;
import org.zkoss.image.AImage;
import org.zkoss.zul.Image;
public class ImageToZkImageConverter implements Converter<AImage, byte[], Image> {
private Log logger = LogFactory.getLog(ImageToZkImageConverter.class);
@Override
public byte[] coerceToBean(AImage compAttr, Image component, BindContext ctx) {
logger.debug("Converting the image");
return compAttr.getByteData();
}
@Override
public AImage coerceToUi(byte[] beanProp, Image component, BindContext ctx) {
try {
if (beanProp != null && beanProp.length > 0) {
AImage im = new AImage("", beanProp);
component.setContent(im);
return im;
}
logger.debug("Return null => image is empty");
return null;
} catch (IOException e) {
logger.error("Error occured, returning null", e);
return null;
}
}
}
Greetz chill.
Asked: 2014-12-16 15:07:16 +0800
Seen: 48 times
Last updated: Dec 17 '14