Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the server path image to PrimeFaces p:graphicImage?

When I retreive server path and show into the p:graphicImage tag, then images are not displayed. Images are loaded into outside the webbapp folder. Server path of the images are like this \\qbsserver\Test Folder\test\car.jpg.

<p:graphicImage value="\\qbsserver\Test Folder\test\\#{image.imageName}" />

How can I make them to display? I am using PrimeFaces 3.0 and JSF 2.0 in Eclipse IDE.

like image 837
Muthu Avatar asked Jun 01 '12 05:06

Muthu


1 Answers

You're making a conceptual mistake. It's not the server who includes and sends the image along with the generated HTML output somehow. It's the webbrowser who downloads the image by its URL as specified in the <img src> when it encounters an <img> tag in the HTML.

So it has really to be a normal URL, exactly the one as the enduser would enter in the webbrowser's address bar, not a server specific local disk file system path. The enduser using the webbrowser really doesn't have that image on exactly that path on its local disk file system.

Easiest would be to add the folder as a "virtual context" of the servletcontainer which you're using. It's unclear which one you're using. In Tomcat it's a matter of adding a new <Context> to the server.xml

<Context docBase="/path/to/images" path="/images" />

and in Glassfish it's a matter of adding an alternatedocroot to the glassfish-web.xml

<property name="alternatedocroot_1" value="from=/images/* dir=/path/to" />

Refer the documentation of the servletcontainer for details. Ultimately they should be accessible by a normal URL so that you can just use for example:

<p:graphicImage value="/images/#{image.imageName}" />

Other ways involve using PrimeFaces StreamedContent API or homegrowing a servlet.

See also:

  • Simplest way to serve static data from outside the application server in a Java web application
like image 168
BalusC Avatar answered Oct 17 '22 17:10

BalusC