[RESOLVIDO] Problema template/facelet JSF Primefaces

2 respostas
R

Fala galera! Alguém pode me ajudar.

Estou tendo problema com este template básico. Ao clicar no botão Ok sou redirecionado para uma tela toda em branco.

Minha pagina de login.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<h:outputScript library="jQuery" name="/js/jquery-1.11.1.js" target="body" />
	<title><ui:insert name="pageTitle">Projeto de Teste</ui:insert></title>
</h:head>
<h:body>
	<p:messages autoUpdate="true" closable="true" />
	<p:growl autoUpdate="true" sticky="true" />
	
	<h:form>
		<p:panel header="Autenticar" style="margin: 0 auto" >
			<h:panelGrid id="gLogin" columns="3" >
				<p:outputLabel id="olLogin" for="itLogin" value="Login" />
				<p:inputText id="itLogin" value="#{loginBean.login}" required="true"
					label="Login" />
				<p:message for="itLogin" />
				
				<p:outputLabel id="olSenha" for="pLogin" value="Senha" />
				<p:password id="pLogin" value="#{loginBean.senha}" required="true" 
					requiredMessage="#{mensagem.validacaoCampoObrigatorio}" label="Senha" />
				<p:message for="pLogin" />
			</h:panelGrid>
			
			<p:commandButton value="Ok" action="#{loginBean.logar}" validateClient="true" update="gLogin" />
		</p:panel>
	</h:form>
</h:body>
</html>

Ao clicar no botão Ok vou para o metodo logar() como descrito abaixo.

public String logar() {
	System.out.println(login);
	System.out.println(senha);
	
	return "/WEB-INF/paginas/corpo";
}

Que redireciono para a pagina corpo.xhtml que tem o insert.

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<h:outputScript library="jQuery" name="/js/jquery-1.11.1.js" target="body" />
	<title><ui:insert name="pageTitle">Projeto de Teste</ui:insert></title>
</h:head>
<h:body>
	<ui:insert name="topo" />
</h:body>
</html>

Que deveria trazer a pagina topo.xhtml que tem um simples menu para confirmar se deu tudo certo.

<ui:composition template="WEB-INF/paginas/corpo.xhtml" 
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
	<ui:define name="topo">
		<h:form>
			<p:menubar>
				<p:submenu label="File" icon="ui-icon-document">
					<p:submenu label="New" icon="ui-icon-contact">
						<p:menuitem value="Project" url="#" />
						<p:menuitem value="Other" url="#" />
					</p:submenu>
					<p:menuitem value="Open" url="#" />
					<p:separator />
					<p:menuitem value="Quit" url="#" />
				</p:submenu>
	
				<p:menuitem value="Quit" url="http://www.primefaces.org" icon="ui-icon-close" />
			</p:menubar>
		</h:form>
	</ui:define>
</ui:composition>

Mas infelizmente não funciona, sou redirecionado para uma pagina toda em branco. Alguém poderia me ajudar?

2 Respostas

R

Alguém pode ajudar?

R

Resolvido pessoal.

Eu estava fazendo errado. Vou fazer uma breve explicação para ajudar quem esteja com a mesma dúvida.

Eu estava fazendo a pagina login.xhtml ser redirecionada para a pagina corpo.xhtml onde estava implementado o meu template. Isto é errado! A pagina definida como template não é carregada diretamente, como se voce passasse o endereço no navegador, ela é carregada dentro de outra pagina.

No meu caso, fiz a pagina corpo.xhtml carregar uma template.xhtml. Pagina esta onde esta definida meu template. Bem, este foi meu entendimento.

Resumindo, fica assim…

Minha pagina de login.xhtml está assim.

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<h:outputScript library="jQuery" name="/js/jquery-1.11.1.js" target="body" />
	<title><ui:insert name="pageTitle">Projeto de Teste</ui:insert></title>
</h:head>
<h:body>
	<p:messages autoUpdate="true" closable="true" />
	<p:growl autoUpdate="true" sticky="true" />
	
	<h:form>
		<p:panel header="Autenticar" style="margin: 0 auto" >
			<h:panelGrid id="gLogin" columns="3" >
				<p:outputLabel id="olLogin" for="itLogin" value="Login" />
				<p:inputText id="itLogin" value="#{loginBean.login}" required="true"
					label="Login" />
				<p:message for="itLogin" />
				
				<p:outputLabel id="olSenha" for="pLogin" value="Senha" />
				<p:password id="pLogin" value="#{loginBean.senha}" required="true" 
					requiredMessage="#{mensagem.validacaoCampoObrigatorio}" label="Senha" />
				<p:message for="pLogin" />
			</h:panelGrid>
			
			<p:commandButton value="Ok" action="#{loginBean.logar}" validateClient="true" update="gLogin" />
		</p:panel>
	</h:form>
</h:body>
</html>

Ao clicar em “Ok” sou redirecionado para a pagina corpo.xhtml que tem um “composition” para o template.xhtml.

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<h:outputScript library="jQuery" name="/js/jquery-1.11.1.js" target="body" />
	<title><ui:insert name="titulo">Título de Teste</ui:insert></title>
</h:head>
<h:body>
	<ui:composition template="/WEB-INF/paginas/template.xhtml">
		
   	</ui:composition>
</h:body>
</html>

Já meu template.xhtml tem os includes das outras paginas. No meu caso da topo.xhtml.

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<h:outputScript library="jQuery" name="/js/jquery-1.11.1.js" target="body" />
	<title><ui:insert name="titulo">Título de Teste</ui:insert></title>
</h:head>
<h:body>
	<ui:insert name="topo">
		<ui:include src="/WEB-INF/paginas/topo.xhtml"/>
	</ui:insert>
</h:body>
</html>

E por ultimo, a pagina topo.xhtml tem um “menu” básico.

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
	<h:form>
		<p:menubar>
			<p:submenu label="File" icon="ui-icon-document">
				<p:submenu label="New" icon="ui-icon-contact">
					<p:menuitem value="Project" url="#" />
					<p:menuitem value="Other" url="#" />
				</p:submenu>
				<p:menuitem value="Open" url="#" />
				<p:separator />
				<p:menuitem value="Quit" url="#" />
			</p:submenu>

			<p:menuitem value="Quit" url="http://www.primefaces.org" icon="ui-icon-close" />
		</p:menubar>
	</h:form>
</ui:composition>

Pois é, resolveu meu problema e espero que ajude quem passar pela mesma situação.

Abração!

Criado 19 de setembro de 2014
Ultima resposta 23 de set. de 2014
Respostas 2
Participantes 1