Configuring contracts in XML

Contracts can be associated with the JSF pages, as you saw in the previous sections. As an alternative, we can accomplish the same thing by configuring contracts in the faces-config.xml file. For example, let's suppose that we have three contracts: default, tableGreen, and tableBlue. Their association with different pages is as follows:

  • The default contract is associated with the tables/defaultTablePage.xhtml page
  • The tableGreen contract is associated with the greenTablePage.xhtml page
  • The tableBlue contract is associated with the blueTablePage.xhtml page

In faces-config.xml, we can do these associations using a few tags—the following example code speaks for itself:

<application> <resource-library-contracts> <contract-mapping> ...

Get Mastering JavaServer Faces 2.2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.