Java Reference
In-Depth Information
@FaceletsResourceResolver Annotation
In some cases, developers require the ability to influence the way that Facelets loads templates. In these
circumstances, developers can specify the javax.faces.FACELETS_RESOURCE_RESOLVER environment parameter in
the web.xml deployment descriptor. Since JSF 2.2 is steering more toward getting away from XML configuration and
more toward annotation usage, the @FaceletsResourceResolver annotation has been created to take place of the old
configuration. While the specification of javax.faces.FACELETS_RESOURCE_RESOLVER in the deployment descriptor
still works, the new annotation makes it easy to register a Facelets resource resolver.
To use the annotation, specify it on a Java class that is intended for use as a resource resolver. By doing so,
Facelets will automatically register the class as a resource resolver. The following source demonstrates the use of the
new annotation.
import javax.faces.application.Resource;
import javax.faces.view.facelets.FaceletsResourceResolver;
import javax.faces.context.FacesContext;
import javax.faces.view.facelets.ResourceResolver;
public class AppResourceResolver extends ResourceResolver {
private ResourceResolver parent;
public AppResourceResolver(ResourceResolver parent) {
this.parent = parent;
public URL resolveUrl(String path) {
System.out.println("Using Custom Resource Resolver");
URL url = parent.resolveUrl(path);
if (url == null) {
if (path.startsWith("/")) {
path = path.substring(1);
url = parent.resolveUrl(path);
return url;
Resource Library Contracts
An enhancement to the JSF resource library has made it easier to include new and/or additional templates for use within
an application. The new enhancement enables multiple templates to be utilized within an application, with the ability to
dynamically or statically define which template is to be applied to specified views. Let's start with the basics of setting up
a resource library contract, and then we'll dive into the various means of applying one or more templates to views.
JSF allows templates to be created by adding a folder named /contracts to the root of an application's web
directory, or into the /META-INF directory. Once added, one or more template directories can be placed inside of the
contracts folder, each containing an associated template file and any optional resource files (CSS, JavaScript, etc.)
Search WWH ::

Custom Search