Alternative stateful theme switchers

By default, PrimeFaces theme switcher only changes the theme on the fly without sending an AJAX or full-page request. Users often want to get notified when the current theme has been changed in order to be able to update user preferences or settings.

In this recipe, we will implement two stateful theme switchers, which are able to save the current selected theme on the server side.

How to do it...

The next listing demonstrates a stateful theme switcher with attached AJAX behavior.

<p:themeSwitcher id="statefulSwitcher1" value="#{userSettingsController.theme}" style="width:165px" effect="fade"> <f:selectItem itemLabel="Choose Theme" itemValue=""/> <f:selectItems value="#{userSettingsController.themes}"/> <p:ajax ...

Get PrimeFaces Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.