HTML and CSS Reference
In-Depth Information
As you can see from Listing 5-11, the resource library contract template is exactly like a normal Facelets template.
Since this template will be the basis of our contract, we must note down and reuse the template file name as well
as the content regions. That is, our template file must be named page-template.xhtml and we must stick to using
<ui:insert name="page-title" /> to insert the title of the page, <ui:insert name="top" /> to insert the header of
the page, and <ui:insert name="content" /> to insert the content of the page. You are free to change everything in the
resource library contract including style sheets and images. The unique name of our resource library contract is the
name of the directory under /contracts , that is, basic. To create another resource library contract, simply create a
directory under /contracts with a unique name containing templates with the same name. Listing 5-12 shows the
structure of the contracts directory after creating the basic-plus contract.
As you can see in Listing 5-13, the template name is the same ( page-template.xhtml ) and the content regions
are the same ( page-title , top , content ). Both basic and basic-plus follow the same contract and can be used by the
same template client.
The resource library contracts are in place and ready for use.
Method 1: Mapping contracts on views through URL patterns
You can specify which contract to use through URL patterns. This is useful when you want to apply different resource
libraries to separate sections or access levels. For example, you may want to apply a separate resource libraries to
anonymous users and administrators. You can map resource library contracts to views in faces-config.xml inside
the applications tag.
In Listing 5-14, the basic resource library contract is applied when accessing views under /admin. All other views
use the basic-plus resource library, which contains more help information.
Listing 5-14. Applying Separate Contracts to Views Accessed Through /admin/* and the Rest of the Views
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns=" http://xmlns.jcp.org/xml/ns/javaee "
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation=" http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd ">
<application>
<resource-library-contracts>
<contract-mapping>
<url-pattern>/admin/*</url-pattern>
<contracts>basic</contracts>
</contract-mapping>
<contract-mapping>
<url-pattern>*</url-pattern>
<contracts>basic-plus</contracts>
</contract-mapping>
</resource-library-contracts>
</application>
</faces-config>
 
Search WWH ::




Custom Search