File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes reading and display an image from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "reading and display an image from database" Watch "reading and display an image from database" New topic

reading and display an image from database

akbar alkarij

Joined: Sep 15, 2013
Posts: 1
I want to display a Image read from the server as byte[]

I read the image in the entity class as byte[] and i want to create a image and save it in server and while clicking a button in jsf page i want to load the image to p:graphicImage
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

Welcome to the JavaRanch, Akbar!

Web images are always fetched via separate URLs. That's what the HTML image tag and its corresponding h:graphicImage tag do, is define the URL from which the image is going to be retrieved.

If your image is already stored in a supported binary image format (such as jpg or gif) within the WAR, all that's needed is to construct a URL that references this image resource.

If you are pulling the image from a BLOB in a database or dynamically constructing the image - for example, as a graph - then you will have to construct a temporary image resource and provide a URL mechanism that retrieves the content of that image.

JSF itself will not be aware of which of the above you are using, since in both cases, a URL is the means of access. Merely that in one case you are using the webapp server's default URL resolution functions and in the other, you're providing a URL resolution function of your own.

An IDE is no substitute for an Intelligent Developer.
Enthu Tarun Singh

Joined: Sep 23, 2013
Posts: 2

I agree with the above comment and doing so will increase performance. If you are intended to load from Data base then you have to read BLOB from data base using InputReader, BufferReder and set that value in the <h:graphicImage />tag of JSF.
I agree. Here's the link:
subject: reading and display an image from database
It's not a secret anymore!