1

My application needs to implement dynamic images, where a browse can get served a JPG or PNG out of my data base.

I have been reading this thread and am not getting very far in learning from it. Can someone provide a link to a tutorial about how to implement a ResourceHandler.

Having looked through all the books Amazon offers on JSF 2.0, none of them seem to cover this topic. Thanks in advance.

UPDATE: This question is withdrawn since I took a different path to the solution, which was simply to implement a Servlet to serve up the images. What I was asking was how to get the JSF Facelets Servlet to response to a GET with a "image/png" media type. Although it seems that you can do that through the ResourceHandler facility, I found that implementing a Servlet is easier, and what's more you have more flexibility with regard to the resource path name.

What I was also surprised about is that although the Servlet doesn't have a FacesContext when it processes a Request, you CAN inject beans or resources that are CDI managed. This gave me the same access to the JPA back end as the rest of the application. So my issue is resolved.

Community
  • 1
  • 1
AlanObject
  • 9,613
  • 19
  • 86
  • 142
  • 1
    A servlet is indeed much easier. You only won't be able to use it with ``/``/`` with a `library` and thus you will miss the relocation and versioning possibilities. – BalusC Apr 11 '12 at 11:24
  • @BalusC Yeah I don't care about that as long as I can generate a book-markable URL to the image to export to other web pages. Back on the original topic, I still haven't found a tutorial/intro to writing a ResourceHandler and I wonder what that guy you were helping in the other thread read to get as far as he did. I've come up with nothing but the javadoc for the package. – AlanObject Apr 11 '12 at 15:11
  • Possible duplicate of [Download file, filename doesn't work in portlet](https://stackoverflow.com/questions/35334589/download-file-filename-doesnt-work-in-portlet) – stiemannkj1 Jan 17 '19 at 16:24

1 Answers1

0

Here are several links to different approaches :

JSF graphicImage from database - Extending the Resource

ImageServlet serving from database

PrimeFaces - Dynamic Images with JSF

Daniel
  • 36,833
  • 10
  • 119
  • 200