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

Writing a theme switcher


If you are a PrimeFaces fan, then I'm sure you have seen the PrimeFaces theme switcher. Basically, a theme switcher is represented by a drop-down menu that contains themes' names and thumbnails. End users can switch between application's themes just by selecting it from the list.

In this section, you will see how to develop a theme switcher using the JSF 2.2 contracts. The goal is to obtain a theme switcher so that:

  • It can be added as a JAR in any JSF 2.2 application

  • It can automatically detect and list the themes of an application

  • It can give a nice look and feel, as shown in the following screenshot (shown on the left-hand side is the PrimeFaces theme switcher, and on the right-hand side is our theme switcher)

Obviously, this kind of a drop-down menu cannot be generated using the built-in <h:selectOneMenu> tag. In order to customize a drop-down menu with images and description, we can write a dedicated Renderer, or try to use a JavaScript plugin capable of rendering...