Eu fiz o que o exercício pediu, mas ainda ele não segura o tema quando troco a página. Faltou algo?
package br.com.caelum.livraria.bean;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class TemaBean {
private String tema = "vader";
public String getTema() {
return tema;
}
public void setTema(String tema) {
this.tema = tema;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head/>
<h:body>
<div id="cabecalho">
<h:graphicImage library="img" name="logo.png"/>
<h:form>
<p:themeSwitcher id="basic" style="width:165px" value="#{temaBean.tema}">
<f:selectItem itemLabel="Choose Theme" itemValue="" />
<f:selectItem itemLabel="Aristo" itemValue="aristo" />
<f:selectItem itemLabel="Vader" itemValue="vader" />
<f:ajax />
</p:themeSwitcher>
</h:form>
<p:growl id="growl" showDetail="true" autoUpdate="true" sticky="true"/>
<h:form rendered="#{usuarioLogado != null}">
<p:menuButton value="Menu">
<p:menuitem value="Livros" action="livro?faces-redirect=true" icon="fa fa-fw fa-edit"/>
<p:menuitem value="Autores" action="autor?faces-redirect=true" icon="fa fa-fw fa-edit"/>
<p:separator />
<p:menuitem value="Logout" action="#{loginBean.deslogar}" icon="fa fa-fw fa-sign-out"/>
</p:menuButton>
</h:form>
<h1><ui:insert name="titulo"></ui:insert></h1>
</div>
<div id="conteudo">
<ui:insert name="conteudo">
</ui:insert>
</div>
<div id="rodape">
Copyright 2018
<ui:insert name="texto">
</ui:insert>
<br />
<h:outputText value="Usuário logado: #{sessionScope['usuarioLogado'].email}"/>
</div>
</h:body>
</html>