I really don’t know if it’s a Netbeans issue but here’s the problem:
In my jsf web app, in the root directory, I have a folder named resources which contains the sub folders images, css and js (for javascript). The subfolders contain the respective content. Here’s how I reference a script (for example) from within the application:
<h:outputScript library="js" target="head" name="dialog.js"/>
Problem is, when I clean and build, while the files in the css directories and js directories are left intact, all the images in the images directory are deleted. How then can I use the jsf resource mechanism if it’ll wipe off my images on every “clean and build”?
JSF doesn’t do that. It’s the server which does that. This problem indicates that you’re manually storing (uploaded?) images in the expanded WAR folder instead of somewhere outside it. A “clean and rebuild” just cleans the server’s work folder and the old expanded WARs and rebuilds the webapp based on the original WAR (essentially, when developing, the project’s structure). This does by the way not only happen in development, but also in production whenever you redeploy a new WAR file.
This behaviour is by specification. You should simply not manually put files in the expanded WAR folder and expect them to magically be included in the original WAR file or to be retained on redeploy.
Store them in a fixed and permanent location outside the WAR. If you add the external path as a new context to the server, then you can just reference them by
<img>or<h:graphicImage value>the usual way.See also Load images from outside of webapps / webcontext / deploy folder using <h:graphicImage> or <img> tag.
If you really need to get them to be resolved by the JSF resource handler, so that you can use them in something like
<h:graphicImage library="uploads" name="foo.png>, then you need to implement a customResourceHandler. It look something like this:To get it to run, register it as follows in
faces-config.xml:This is however not exactly trivial to summarize off top of head in a single answer. You also need to understand how HTTP (caching) works. Just read the javadocs, starting at
ResourceHandler, and peek around in Mojarra’s ownResourceHandlerImplandResourceImplsource codes to get the idea.