HTML and CSS Reference
In-Depth Information
It is possible to map multiple contracts to a single mapping. In that case, it will go through each contract
sequentially to look for the required templates. Once a template has been found it will stop processing the other contracts.
Method 2: Specifying the contracts on each view
By specifying the contract on each view you can make your application skinnable by the user. That is, you can allow
the user to select which contract to apply for your application. You apply contracts to template clients by enclosing
the view in an <f:view /> tag where you specify the name of the contract to apply in the contracts attributes, e.g.
<f:view contracts="basic"> . You can replace the explicit declaration of the view contract but using an EL binding,
e.g. <f:view contracts="#{userSession.contract}"> , as shown in Listings 5-15 and 5-16.
Listing 5-15. Allowing the User to Select the Contract to Apply to the View
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" " >
<html xmlns=" "
xmlns:h=" "
xmlns:ui=" "
xmlns:f=" "
xmlns:p=" " >
<f:view contracts="#{userSession.contract}">
<ui:composition template="/page-template.xhtml">
<ui:define name="page-title">Welcome to JSF 2.2</ui:define>
<ui:define name="content">
Select a template
<h:selectOneRadio value="#{userSession.contract}" layout="pageDirection"
<f:selectItem itemValue="basic" itemLabel="Basic" />
<f:selectItem itemValue="basic-plus" itemLabel="Basic Plus" />
<h:commandButton value="Save" />
<ui:define name="top">Template: #{userSession.contract}</ui:define>
Listing 5-16. Session-Scoped Managed Bean Used for Storing the Selected Contract
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
public class UserSession {
Search WWH ::

Custom Search