aspose file tools
The moose likes JSF and the fly likes Images not displaying using JSF? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Images not displaying using JSF?" Watch "Images not displaying using JSF?" New topic
Author

Images not displaying using JSF?

Joseph Henstay
Greenhorn

Joined: Mar 31, 2005
Posts: 5
Hey all,
I'm not a java programmer, I'm just an administrator for some WebSphere servers, so I'm hoping someone here can help me out.

This guy developped a Java Application which has the context-root of /SomeApp. This is the first application we are deploying using a Java Server Faces implementation. In main JSP's he includes a couple other JSP's like such:

<jsp:include page="header.jsp" />

In this included JSP, he has html code such as:

<img src="images/appimage.jpg">

Well, now what's happening is when the page loads, it's looking for the image using the following URI:

/context-root/faces/images/appimage.jpg

such as:

/SomeApp/faces/images/appimage.jpg

The question is, why is it inserting "faces" into the URI? This developer claims it's a configuration issue on WebSphere and claims there's NOTHING he can do about it. He also says it works fine on his laptop, but he has fileServing enabled there, so obviously it would work.

The reason that this is an issue is that we run all of our applications with fileServing disabled, so the images, style sheets, etc, all get served up by Apache and not Websphere. In the past we've simply included Alias's in the httpd.conf for the context-root/images to point to the correct location on the filesystem, however, with this faces implementation, it apparently defaults in the web.xml so that all of context-root/faces/* goes to Websphere.

Any help on this is greatly appreciated.

Thanks!
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
I too use websphere, my images path are like "/images/individual.gif" in the h:graphicImage and it works perfectly for me.

I am bit confused over whether you are using JSF image component for displaying images or an html tag?


- Varun
Joseph Henstay
Greenhorn

Joined: Mar 31, 2005
Posts: 5
Varun,
Thanks for the reply. I've been looking at this developers code and it looks like the main page that he is displaying is using the JSF markup like you show there, however, in that page, he has that <jsp:include page="header.jsp" /> line, but in header.jsp, he is NOT using any of the JSF markup code, it looks like he is using straight HTML in there. Is that the problem? Should he be using the JSF markup code instead of a regular HTML image tag in the included JSP?

Thanks again!
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
using a / before makes the location of the images file relative to the context root. For example /images/whatever.gif will actually be read as
/context-root/images/whatever.gif. When not using the /, you are specifying that the images directory is relative to the current directory that the calling jsp is located in. For example, if you call images/whatever.gif from the whatever.jsp located in the /context-root/faces directory the call to images/whatever.gif is actually a call to /context-root/faces/images/whatever.gif.


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by Joseph Henstay:
Varun,
Thanks for the reply. I've been looking at this developers code and it looks like the main page that he is displaying is using the JSF markup like you show there, however, in that page, he has that <jsp:include page="header.jsp" /> line, but in header.jsp, he is NOT using any of the JSF markup code, it looks like he is using straight HTML in there. Is that the problem? Should he be using the JSF markup code instead of a regular HTML image tag in the included JSP?

Thanks again!


I feel that your header.jsp has not even a single JSF component, is that the case?
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by William Duncan:
using a / before makes the location of the images file relative to the context root. For example /images/whatever.gif will actually be read as
/context-root/images/whatever.gif. When not using the /, you are specifying that the images directory is relative to the current directory that the calling jsp is located in. For example, if you call images/whatever.gif from the whatever.jsp located in the /context-root/faces directory the call to images/whatever.gif is actually a call to /context-root/faces/images/whatever.gif.


Your point in right, but in JSF worlds when you say /ctx-root/faces/images .. it normally means your directory strcture is /ctx-root/images

the /faces is used to tell conainer that this request should be handled by FacesServlet [by configering the servlet-mapping/url-pattern in web.xml file].
Joseph Henstay
Greenhorn

Joined: Mar 31, 2005
Posts: 5
Varun,
Yes, you are correct that it looks like header.jsp does not have any JSF in it at all.

Ok, then my question is, how come when we access the main.jsp page, which has JSF in it and includes header.jsp, which doesn't have any JSF code in it (other than listing the taglibs in the <HEAD> and header.jsp has the line:

<img src="images/appimage.jpg">

When we view the source of the page in the web-browser, the URL listed for the image is:

http://server.name.here/context-root/faces/images/appimage.jpg

Why is it changing it to include "faces" in the URL name? Is that something that is a part of JSF where it automatically prepends relative URL's with "faces"?

Thanks again for all of your help!
Joseph Henstay
Greenhorn

Joined: Mar 31, 2005
Posts: 5
Varun,
Thanks for all of your help. I went and modified the developers code and changed it to utilize the HTML tags in JSF and sure enough, that fixed it!

Thanks again!
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Great.
Joseph Henstay
Greenhorn

Joined: Mar 31, 2005
Posts: 5
William,
Thanks for your reply as well. We tried this and that corrects the issue as well. Thanks again!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Images not displaying using JSF?
 
Similar Threads
java.lang.IllegalStateException: using sendRedirect()
Problem with Simple Facelet
Having serious trouble configuring Authorization
Changing <context-root>
jsp:param not working inside jsp:include and JSF