webtier@glassfish.java.net

Re: Images, databases and jsf - how to make it work?

From: Joel Weight <digitaljoel_at_gmail.com>
Date: Thu, 9 Feb 2012 09:45:09 -0700

Primefaces graphic image
http://www.primefaces.org/showcase/ui/dynamicImage.jsf is supposed to be
able to load the image from the database, but I can't guarantee because I
haven't used it. Back when I was doing JSF (been a while now) I hijacked
the h:graphicImage tag so that it would perform as usual, or load form the
database depending on the library. I wrote a blog post about it:
http://digitaljoel.nerd-herders.com/2010/09/12/jsf-graphicimage-from-database/

If the primefaces component will work for you it's definitely easier than
the way I did it. As for upload, I echo what Jason said.

Joel

On Thu, Feb 9, 2012 at 9:18 AM, Jason Lee <jason.d.lee_at_oracle.com> wrote:

> On 2/9/12 9:43 AM, forums_at_java.net wrote:
>
>> I want to extract pictures from the table and display them in a jsf page;
>> I
>> know how to go about database tables etc in general in Java EE, but I am
>> not
>> sure about images - is there a place I can read more about it? Or is it
>> just
>> really simple?
>>
> There are probably several ways you can do it. The easiest might be a
> simple Servlet. You construct URLs that point to this Servlet, which reads
> the data from the database and returns it to the user, setting all the
> proper headers, etc. If you want a more JSF-ish way to do it, this old
> blog post of mine might help: http://blogs.steeplesoft.com/**
> 2010/05/putting-facelets-in-a-**jar/<http://blogs.steeplesoft.com/2010/05/putting-facelets-in-a-jar/>
>
> That post notes that it doesn't directly address database access, but,
> hopefully, there's enough there to get you going if you choose that route.
> A Servlet is probably simpler. :)
>
> Another things is - how about uploading pictures, which is the other,
>> important part of this?
>>
> Currently, JSF doesn't have file upload support built in. JSF 2.2, which
> is due out sometime "soon" will fix that. I'm guessing you need it now,
> though. :) There are several blog entries around the web describing how to
> roll your own solution, but if you're not opposed to a third party JSF
> component library, both RichFaces and ICEfaces have great file upload
> components that should meet your needs.
>
> --
> Jason Lee
> Senior Member of Technical Staff
> GlassFish Team
>
> Oracle Corporation
> Phone +1 405-216-3193
> Blog http://blogs.steeplesoft.com
>
>