Book Image

Mastering JavaServer Faces 2.2

By : Anghel Leonard
Book Image

Mastering JavaServer Faces 2.2

By: Anghel Leonard

Overview of this book

Table of Contents (20 chapters)
Mastering JavaServer Faces 2.2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The JSF Life Cycle
Index

Styling contracts across different devices


In the preceding examples, we saw how to write the JSF contracts and how to use them by explicitly setting them by name in the contracts attribute of the <f:view> tag. Sometimes, you may need to dynamically set a contract (theme); for example, you may need to choose the right contract based on the device type that should display the application (PC, tablet, smartphone, mobile phone, and so on). In this case, you need to provide the contracts attribute value from a managed bean.

It is beyond the scope of this book to provide a powerful code (or algorithm) for detecting device types, resolutions, and so on. With minimum involvement in the mobile area, we will try to write a JSF application capable of choosing the right contract depending on the device type. Practically, we will define the following four contracts (do not consider the following associations between resolutions and devices as a certified or authorized decision):

  • contracts/browserpc...