File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Displaying an image BLOB in my JSF page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Displaying an image BLOB in my JSF page" Watch "Displaying an image BLOB in my JSF page" New topic
Author

Displaying an image BLOB in my JSF page

nakatami stars
Greenhorn

Joined: Mar 01, 2011
Posts: 3

Hello,

I am a beginner in JSF, and I wnat todisplay a picture loaded from my Data Base in my JSF page.

I follow this steps to get my image from my DataBase but I don't know how can I put it in my JSF page:

1/My image is stored in my Data base (Blob type)

2/I load this image from my database and Finally It stored it as a ObjectInputStream;

3/I don't know how can I display it in my JSF page because I don't know what I ll put in the url <h:graphicImage id="image" url="?"/>

please help me.
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
What you will find is that as a beginner it is going to be extremely difficult to do this. Do
not take these words lightly. Is this your primary objective or just one of the things you
have been tasked with?
nakatami stars
Greenhorn

Joined: Mar 01, 2011
Posts: 3
Thanks for replaying.

I am developping a project, so I decided to use JSF because I see that this freemwork make tasks easy. So I stoped when I faced this problem.

Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218

This code demonstrates the loading & display of a BLOB from a database using h:graphicImage
without any temporary files. Whilst not entirely generic you should be able to get this working
with a days work if you're prepared to stick at it.

The scenario is that you have an "Employee" JPA persistent entity that implements the
"PhotoInterface" interface that defines one method, getPhoto(). Given a database with a table
with an integer primary key, where the entity implements PhotoInterface this will display a
byte[] as an image on your page.

"yourEJB" is simply an EJB that has a find function which is EntityManager.find().

Replace or remove SQLog.log() with your logging approach.

In the example below we have an "Employee" entity that supports the PhotoInterface and
therefore has a getPhoto() function. The Employee class (@Entity) has a byte[]
photo property.

In this way you can retrieve images from any entity/table that supports PhotoInterface
given the primary key of the table row.







Regards,
Brendan.
nakatami stars
Greenhorn

Joined: Mar 01, 2011
Posts: 3
Thank you
kikoo kikoooo
Greenhorn

Joined: Mar 17, 2011
Posts: 2
you can use a librairie component for jsf like primefaces and you can do it easy

you can find exemple here http://jeebestpractices.blogspot.com/
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218

It's not like I wrote the code for fun. The issue was that the PrimeFaces fileUpload component
was not working with container security, or on a page with more than one view parameter.

Cagatay has asked me to test the latest version which I will do at some point.

Brendan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying an image BLOB in my JSF page