Skip to content
Adam Warski
Adam Warski

Sharing elegant solutions to everyday problems

  • Home
  • Talks
  • Videos
  • About
Adam Warski

Sharing elegant solutions to everyday problems

Instant Facelets: changes in .xhtml and no redeploying

Adam Warski, 7 December, 20077 December, 2007

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;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @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) {
            e.printStackTrace();
            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:

    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.REFRESH_PERIOD</param-name>
        <param-value>0</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.RESOURCE_RESOLVER</param-name>
        <param-value>org.jboss.shotoku.web.FilesystemResourceResolver</param-value>
    </context-param>

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.

Adam

Share this:

  • Twitter
  • LinkedIn
  • Facebook
  • Reddit
  • Email
  • Mastodon
Java JBoss Uncategorized

Post navigation

Previous post
Next post

CTO @ SoftwareMill

©2023 Adam Warski | WordPress Theme by SuperbThemes