O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using the stateless ThemeSwitcher component

Let us see how we can change theme dynamically using the ThemeSwitcher component.

  1. Create a <p:themeSwitcher> component by providing list of theme names as options:
    <p:themeSwitcher style="width:165px">  
      <f:selectItem itemLabel="Choose Theme" itemValue="" />  
      <f:selectItems value="#{userPreferences.themes}" />  
    </p:themeSwitcher>
  2. Implement a managed bean method to return the list of all Primefaces supporting theme names:
    @ManagedBean @SessionScoped public class UserPreferences implements Serializable { private List<String> themes; public UserPreferences() { themes = new ArrayList<String>(); themes.add("afterdark"); themes.add("afternoon"); themes.add("afterwork"); themes.add("aristo"); themes.add("black-tie"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required