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........)
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.