logo       

Re: Creating templates in jar files: msg#00075

java.facelets.user

Subject: Re: Creating templates in jar files


I would like to create custom taglibs with the help of facelets in
separate jars.
Is it possible to load the xhtml files with ui:include from the
classpath?

I mean something like this:
<ui:include source="classpath://com/x/y/datascroller.xhtml">

Would be nice to use something similar when I create taglibs in the
source xml element.


Yes. Use a custom resource resolver. Like this one:

public class ClassletsResourceResolver extends DefaultResourceResolver {

public ClassletsResourceResolver() {
super();
}

private static final String PREFIX = "/classlets/";

public String getPrefix() {
return PREFIX;
}

public URL resolveUrl(String path) {
final String prefix = getPrefix();
if (path != null && path.startsWith(prefix)) {
final String resource = path.substring(prefix.length());
final URL url = getClass().getClassLoader().getResource(resource);
return url;
} else

{
return super.resolveUrl(path);
}
}
}

I have something similar in my Seamless utility library, except it checks the classpath only if the template isn't found on the filesystem:

http://seamless.ninthavenue.com.au/xref/seamless/util/FaceletsJarResolver.html
http://www.ninthavenue.com.au/extras/seamless

To change the facelets resolver you need to set a context parameter in your web.xml, like this:

<!-- allows facelets to be in jars -->
<context-param>
<param-name>facelets.RESOURCE_RESOLVER</param-name>
<param-value>seamless.util.FaceletsJarResolver</param-value>
</context-param>

As somebody mentioned in this thread, you don't need to do this for custom tags as they are already resolved relative to the taglib file, even if this is in a jar.

Roger


--
----------------------------------------
Ninth Avenue Software
p: +61 7 3137 1351 (UTC +10)
f: +61 7 3102 9141
w: http://www.ninthavenue.com.au
e: info@xxxxxxxxxxxxxxxxxx
----------------------------------------


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise