Howto show and save image as blob type with seam

Johan Tuitel 1

In a project where i am working on, we needed to show an image and the image should be change when a user would like to do that. For that we need to hava an attribute in a table called photo and it has to be a blob. See below:

We have now a photo attribute as a blob, the next thing we need to do, is to make an entity with a photo attribute. The entity is called Person and has a byte[] variable called photo. See below for an example:

public class Person{
private byte[] photo = null;

public byte[] getPhoto(){
return photo;

public void setPhoto(byte[] photo){ = photo;

For the front-end we need to make a page with the next part(just make a simple xhtml page):
<h:panelGrid columns=”2″>
<s:graphicImage id=”currentImage” value=”#{}”
rendered=”#{ != null}” styleClass=”vpaPhoto” />
<s:graphicImage id=”defaultImage” value=”/img/default.png”
rendered=”#{ == null}” styleClass=”vpaPhoto” />
<s:fileUpload id=”imageUploader” data=”#{}” onchange=”submit()” styleClass=”imageUploader”  />

The appearance should look like this(you can choose any picture you would like for the default.png file):

Ok and now we click on browse an select an image(i’ve downloaded one from google, m_mylle.jpg)

So i’ve selected the m_mylle.jpg file and then i click open. The result is shown below:

Good luck, all suggestions and improvements are welcome.

One thought on “Howto show and save image as blob type with seam

Comments are closed.

Next Post

Accessing JVM arguments from Java (to determine if JVM is running in debug mode)

Facebook0TwitterLinkedinThe other day, I was using the JDeveloper debugger to locally debug some code in an application that uses (and therefore becomes part of) an Oracle Coherence data grid. As it turned out, using step-by-step debugging in a JVM that is part of a Coherence cluster has significant impact on the […]