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

posted Mar 01, 2011 22:30:28

0

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

posted Mar 02, 2011 07:02:54

1

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.