Pessoal,
Sou novato no JSF e estou tendo um probleminha quando clico no menu “Cliente” a página do mesmo não é exibida.
Abaixo segue o fonte para poderem ter uma idéia do que estou falando…
Debugando vejo que os métodos ‘cliente’ e ‘getPaginaAtual’ de MenuController são chamados quando eu clico no menu
Cliente, mas continua ‘em branco’. Se eu colocar fixo “cliente.xhtml” no lugar de “#{menuController.paginaAtual}” a página
do Cliente é exibida (esse trecho está indicado com comentário).
template.xhtml
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:sec="http://www.springframework.org/security/facelets/tags">
<h:head>
<title>titulo</title>
</h:head>
<h:body>
<ui:insert name="headerpage">
</ui:insert>
<ui:insert name="actualpage">
Actual page here...
</ui:insert>
</h:body>
</html>
--------------------------------------------------------------------
main.xhtml
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:sec="http://www.springframework.org/security/facelets/tags">
<body >
<ui:composition template="template.xhtml">
<ui:define name="headerpage">
<ui:include src="menu.xhtml"/>
</ui:define>
<ui:define name="actualpage">
<ui:include src="#{menuController.paginaAtual}"/> <!--Aqui se eu coloco direto "cliente.xhtml" a pagina do cliente é exibida-->
</ui:define>
</ui:composition>
</body>
</html>
--------------------------------------------------------------------
menu.xhtml
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:sec="http://www.springframework.org/security/facelets/tags">
<body >
<h:form>
<p:menubar>
<p:submenu label="Cadastro" icon="ui-icon ui-icon-document" rendered="#{sec:ifAnyGranted('ADMIN,SUPERVISOR,COMUM')}" >
<p:menuitem value="Cliente" action="#{menuController.cliente}" rendered="#{sec:ifAnyGranted('ADMIN,SUPERVISOR,COMUM')}" />
</p:submenu>
</p:menubar>
</h:form>
</body>
</html>
--------------------------------------------------------------------
cliente.xhtml
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
</h:head>
<body >
<h:form prependId="false" >
<p:growl id="growlMessage" showDetail="true" />
<p:panel header="Cliente">
<h:panelGrid columns="3" >
<h:outputLabel for="tfNome" value="Nome: " />
<p:inputText id="tfNome" />
<h:message for="tfNome" errorClass="error"/>
<h:outputText value="" />
<p:commandButton type="submit" id="btnSalvar" value="Salvar" update="growlMessage" />
</h:panelGrid>
</p:panel>
</h:form>
</body>
</html>
--------------------------------------------------------------------
MenuController
@ManagedBean
@SessionScoped
public class MenuController {
private String paginaAtual = null;
public void setPaginaAtual(String paginaAtual) {
this.paginaAtual = paginaAtual;
}
public String getPaginaAtual() {
return paginaAtual;
}
public void cliente() {
setPaginaAtual("cliente.xhtml");
}
}