Instant Facelets: changes in .xhtml and no redeploying

If you are developing anything with Facelets/Seam/… frameworks, you probably know the pain of having to redeploy after each .xhtml file change to see the changes, even if they are only cosmetic. I wrote about possible solutions for that problem earlier, but they didn’t quite work for facelets (more specifically, templates didn’t get refreshed and any included pages).

Of course, the best solution is to try JBoss Tools and Red Hat Developer Studio. However if you want to use IDEA, or some other IDE (vi? :) ), try the following.

The trick is to tell Facelets to read the files from disk. Sounds simple, and Facelets have built-in mechanisms which make it simple.

First, you have to implement the ResourceResolver interface:

package org.jboss.shotoku.web;

import com.sun.facelets.impl.ResourceResolver;


 * @author Adam Warski
public class FilesystemResourceResolver implements ResourceResolver {
    public URL resolveUrl(String s) {
        try {
            return new URL("file", "",
                  "PATH_TO_FACELETS_FILES_GOES_HERE" + s);
        } catch (MalformedURLException e) {
            return null;

and replace the path to your Facelets directory in the appropriate place (absolute path, for example /home/user/mygreatapp/view). (It is also easy to externalize that configuration using a context parameter.)
Then, to your web.xml you have to add:


And you’re done! Try editing a .xhtml page (or template, or included page) and refreshing your browser.

If you want also other resources to be read from disk (like css files), try the Resources Filter.