-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am getting data from database and show on listbox.But there is a problem . My problem is showing an image that got from database.How to show an image on my listbox?My entity is here;
@Entity
@Table(name = "kitaplar")
@NamedQueries({
@NamedQuery(name = "tumkitaplarigetir", query = "SELECT k FROM Kitaplar k"),
@NamedQuery(name = "findLastBook", query = "SELECT k FROM Kitaplar k ORDER BY k.kitapId desc") })
public class Kitaplar implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "kitapid")
private int kitapId;
@Column(name = "kitapad")
private String kitapad;
@Column(name = "yazarad")
private String yazarad;
@Column(name = "kitaptur")
private String kitaptur;
@Column(name = "kitapdurum")
private String kitapdurum;
@Lob
@Column(name = "kitapimage")
private byte[] kitapimage;
and my listbox;
<listbox id="kitapListBox" emptyMessage="Kayıt yok!"
mold="paging" pageSize="5" width="970px"
apply="com.mesutemre.kitapIslemleri.KitapListesiControl"
model="${win$composer.kitapListModel}">
<listhead>
<listheader label="Kitap Adı" align="center"
sort="auto(kitapad)" width="190px" />
<listheader label="Yazar Adı" align="center"
sort="auto(yazarad)" width="190px" />
<listheader label="Kitap Tür" align="center"
width="190px" sort="auto(kitaptur)" />
<listheader label="Kitap Durum" align="center"
sort="auto(kitapdurum)" width="190px" />
<listheader label="Kitap Resmi" align="center"
width="190px" />
</listhead>
<template name="model">
<listitem>
<listcell label="${each.kitapad}" />
<listcell label="${each.yazarad}" />
<listcell label="${each.kitaptur}" />
<listcell label="${each.kitapdurum}" />
<listcell>
<image id="kitapImageId" />
</listcell>
</listitem>
</template>
</listbox>
do it in the getter of the image.
public getImage(){ return Base64Encoded bytes }
<image src="each.image></p> ">
Something like this:
zul:
<image src="@load(vm.imageAsBytes)" width="100px" height="100px"/>
ViewModel:
public String getImageAsBytes() {
String s = "data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAZABkAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAeAB4DASIAAhEBAxEB/8QAGQAAAgMBAAAAAAAAAAAAAAAABAYDBQcC/8QAKxAAAgEDAwEHBAMAAAAAAAAAAQIDBAURABIhUQYiMUFxgbEHExQjF6Hw/8QAGAEAAwEBAAAAAAAAAAAAAAAAAgMEBQb/xAAjEQACAQMBCQAAAAAAAAAAAAABAgADESEEBRIUFSIxMoGh/9oADAMBAAIRAxEAPwByNP0B1w1Jny0g31O0XZKWFqi4wSCodwppZAVBU8goVAGM+XQ6lsv1ErYKhkuFLBWxryc/qY+44/rVy7VW5DqR9kXBOe0c3oQfLQ0tvyeF1BS/Ue0pvlkt0wde8I8hgPfj40R/JlmrqONmtrbwfCHHh68adzSmDYGLOkI8sGZpfbu98vTXK3pUxRGZ/ttJkhC3eKgjGGPe4z8aHairZJJZaxQj5/bvlSF256OffOD8alsHZ556iQ3T7NUrEOsZZtpbBG5iRknGrZ7BbvyGMsbkcARI5VF9BrmmCk4mytJhkmE0NtssgWncSEMgw6SxyMZNo7pYDwJyDz10sVNVSWtFo1xLImFkdgDlhkdP9xq4rK6C2RmnoqZYyX2YAwN2M5PmfHWf1jmS6VMjk5ZiSPU6J2PuBUbcHTP/2Q==";
return s;
}
Hello emreturka,
A very good tutorial that will help you out can be found at the following url:
http://ben-bai.blogspot.gr/2012/08/java-convert-image-to-base64-string-and.html
Best Regards,
Darksu
Asked: 2015-02-20 09:41:19 +0800
Seen: 23 times
Last updated: Feb 21 '15