File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Handling of paths (CSS, images, ...) with JSF 1.2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Handling of paths (CSS, images, ...) with JSF 1.2" Watch "Handling of paths (CSS, images, ...) with JSF 1.2" New topic

Handling of paths (CSS, images, ...) with JSF 1.2

Karsten Wutzke
Ranch Hand

Joined: Jul 20, 2010
Posts: 106


I'm constructing an admin tool on top of my read-only pages. I put the admin .xhtml pages into a separate sub folder in the root dir:

This is a pretty basic structure (on the server).

Now the question: how do you best handle paths to resources from various directories in the hierarchy, here the root dir and the admin dir?

Example footer footer.xhtml:
The footer is included from /admin/home.xhtml and /team-list.xhtml, so from the root dir files the images work and from the admin files they don't. For whatever reason prefixing with a slash
neither works in the root nor the admin dir (image not found). Same with CSS of course.

I know JSF 2 comes with extensions concerning resources like the above by using library="...", but how is it done in JSF 1.2? Is it really necessary to somehow prefix all paths with a custom value depending on who is the "caller" (client)? I have the feeling I am missing something very fundamental about JSF/Facelets here, but I've had no luck finding out what it is.

Can anybody clear this up for me? (The biggest question to me still is why paths like "/images/..." don't work........)


OCJP JavaSE 6 (86%)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

The main problem is that the absolute URL root is the URL for the entire webapp server, not a specific webapp within the webapp server. So to properly address items, you either need to use relative URLs (if possible), or you need to ensure that the URL includes the webapp context root part of the absolute URL path.

In the case of JSF hyperlinks, JSF will construct the proper URL for you if you use the JSF h:outputLink element. For CSS, scripts, and other static content, I've been known to setup an EL expression in the link, so that I can shift the app between different test and production servers without manual mods to the app. However, some extension tagsets such as RichFaces also provide support of this nature even in JSF 1.2.

An IDE is no substitute for an Intelligent Developer.
Consider Paul's rocket mass heater.
subject: Handling of paths (CSS, images, ...) with JSF 1.2
It's not a secret anymore!