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 listener="#{userSettingsController.saveTheme}"/> </p:themeSwitcher>
Another advanced theme switcher supports displaying theme previews in the form of small images.
We can develop...