0

Getting Image from DB and view on listbox

asked 2015-02-20 09:41:19 +0800

emreturka gravatar image emreturka
9 2

updated 2015-02-20 09:43:32 +0800

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>
delete flag offensive retag edit

4 Answers

Sort by » oldest newest most voted
0

answered 2015-02-20 11:36:44 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

do it in the getter of the image.

public getImage(){ return Base64Encoded bytes }

<image src="each.image&gt;&lt;/p&gt; ">

link publish delete flag offensive edit
0

answered 2015-02-20 12:38:36 +0800

emreturka gravatar image emreturka
9 2

Hi @terrytornado . Can you give me an example.I didn't understand returning Base64.

link publish delete flag offensive edit

Comments

Because my return type is byte[]

emreturka ( 2015-02-20 12:46:01 +0800 )edit
0

answered 2015-02-21 13:15:00 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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;

}

link publish delete flag offensive edit

Comments

Terry, It should be content in stead of src ;)

chillworld ( 2015-02-21 21:35:18 +0800 )edit
0

answered 2015-02-21 17:43:21 +0800

Darksu gravatar image Darksu
1991 1 4

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

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-02-20 09:41:19 +0800

Seen: 23 times

Last updated: Feb 21 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More