HTML and CSS Reference
In-Depth Information
Using resource library contracts, you can map templates to specific views in your application. You could for example
use separate templates and resources for anonymous and authenticated users or for different sections of your
application. Like normal resources, you can include resource library contracts in your application in the contracts/
directory or by packaging the contracts in a JAR file in the META-INF/contracts directory. Place the JAR file in the
WEB-INF/lib directory and it will automatically be discovered by the application.
to speed up discovery of resource library contracts, place a file named javax.faces.contract.xml inside
the directory containing the contract. Currently the file doesn't have any contents, but that may change with an
upcoming version.
There are two methods of using contracts. The first method will automatically map contracts on views through
URL patterns. The second method explicitly declares the contract in the view. The methods can be combined to
achieve maximum flexibility. First, we will look at how to create resource library contracts; then, we will look at the
two methods for applying them in an application.
The goal of resource library contracts is to make available a set of templates that can be reused by template
clients that are unaware of the exact template being used from the available resource library contracts. The resource
library contracts should therefore use identical template and content region names. That is, template files must have
the same file name, and the <ui:insert /> tags must use the same names.
As an example we will create two contracts in an application. The first contract is implemented in Listings 5-10
and 5-11, and the second contract is implemented in Listings 5-12 and 5-13. The difference in the two templates is the
color scheme and help texts.
Listing 5-10. File Structure of the “Basic” Resource Library Contract in the Application Directory
| contracts/
| contracts/basic/page-template.xhtml
| contracts/basic/layout.css
| contracts/basic/page.css
Listing 5-11. Contents of contracts/basic/page-template.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" " >
<html xmlns=" "
xmlns:p=" "
xmlns:jsf=" "
xmlns:ui=" "
xmlns:h=" " >
<h:outputStylesheet name="page.css" />
<h:outputStylesheet name="layout.css" />
<title> <ui:insert name="page-title" /> </title>
<div id="top" class="top">
<ui:insert name="top" />
Search WWH ::

Custom Search