testbunny
testbunny

Reputation: 127

Displaying an image from Local Network to JSF Web Application

I've some image file in my Local Network and I want to display them in the DataTable in JSF. I'm using JSF2.0 and Tomahawk 1.1.13. Below is the JSF code.

    <t:dataTable newspaperColumns="3" value="#{startupBean.colorList}"     newspaperOrientation="horizontal" var="colorBO">

    <f:facet name="spacer">
   <f:verbatim></f:verbatim>
   </f:facet>
   <h:column>
    <h:graphicImage id="colors" alt="jsf-sun" url="#{colorBO.color_url}"> 
    </h:graphicImage>
    </h:column>
    </t:dataTable>

I'm giving the path of the file as "\\root\sub\sub\xxx.jpg" in my backing bean. But when the JSF page renders, it displays a default icon. When I right click on the icon and check the properties, the below is what I get.

http://localhost:8080/projname//root/sub/sub/xxx.jpg

I tries using both backslash and forward slash in the path name. No change in the output though. I dont' know how the http part gets into the file path. I'm missing something for sure.

Upvotes: 1

Views: 1329

Answers (1)

BalusC
BalusC

Reputation: 1108632

You're making a conceptual mistake here. It's the webbrowser who has to download the image separately by a valid and reachable URL once it encounters a <img> element, it's not the webserver who has to somehow magically embed the image from the local disk file system within the HTML page which is returned to the webbrowser.

You need to make the image available by a valid and reachable URL, so that the webbrowser can download it. A local disk file system path is surely not a valid and reachable URL. Even more, it would be a huge security hole if a server machine's local disk file system contents was automagically fully exposed into the world wide web.

One of the simplest ways of solving this problem is just placing the image in the public webcontent (there where your JSF files also are), so that it's available in the web.

Another way is to configure the server to publish the folder into the web so that it's available by a specific URL as well. It's unclear which server you're using, so here's just a Tomcat example:

<Context docBase="/root/sub/sub" path="/images" />

This way the image is available by http://localhost:8080/images/xxx.jpg and then this <h:graphicImage> approach should work:

<h:graphicImage src="/images/xxx.jpg" />

See also:

Upvotes: 2

Related Questions