Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Facelets uses a plugable resource resolver (where the resource is the view template). You simply provide your own implementation of the Facelets ResourceResolver interface and have it look in any classloader to locate the resource.

Here's an example implementation that extends the default implementation to load templates from the classpath that don't begin with a forward slash, otherwise delegating to the default resolver:

import com.sun.facelets.impl.DefaultResourceResolver;
import com.sun.facelets.impl.ResourceResolver;
 
public class CustomResourceResolver extends DefaultResourceResolver implements ResourceResolver
{
    @Override
    public URL resolveUrl(String resource)
    {
        URL resourceUrl = super.resolveUrl(resource);
        if (resourceUrl == null)
        {
            if (resource.startsWith("/"))
            {
                resource = resource.substring(1);
            }
            resourceUrl = Thread.currentThread().getContextClassLoader().getResource(resource);
        }
        return resourceUrl;
    }
}

Then register the custom resolver with Facelets by defining a special context parameter in web.xml.

<context-param>
	<param-name>facelets.RESOURCE_RESOLVER</param-name>
	<param-value>CustomResourceResolver</param-value>
</context-param>

You can of course invent your own resolver strategy. You might even decide to fetch the resource from a remote URL or database.

A full example of creating a shared Facelets JAR file can be found in this post courtesy of OCPsoft.