Book Image

Primefaces Cookbook Second Edition

Book Image

Primefaces Cookbook Second Edition

Overview of this book

Table of Contents (20 chapters)
PrimeFaces Cookbook Second Edition
Credits
Foreword
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Stateless and stateful theme switchers


Multi-theme web applications require a theme switcher component. The default PrimeFaces' theme switcher is a component which enables switching themes on the fly, without sending an AJAX or a full-page request. We speak about a stateless theme switcher because the current selected theme is only known on the client side. Users also often need a stateful theme switcher to save the chosen theme on the server side in user preferences or settings.

In this recipe, we will show the usage of a stateless theme switcher and implement a stateful theme switcher, which is able to save the current selected theme on the server side.

How to do it…

The theme switcher usage is very similar to the usage of p:selectOneMenu. The component is represented by the p:themeSwitcher tag and accepts f:selectItem or f:selectItems. The code snippet for a stateless theme switcher is as follows:

<p:themeSwitcher style="width:165px" effect="fade">
  <f:selectItem itemLabel="Choose...