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.