JSF 2.0 + Primefaces 3.1.1 ( Dúvida com templates )

6 respostas
Tuanny_Ramos

Olá,

tenho uma dúvida de iniciante:

Por que o código abaixo renderiza o Primefaces

<!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:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>

<h:body>
	<h:form>
		<h3>Simple Panel</h3>
		<p:panel header="F.C. Barcelona" footer="Visca el Barca!">
			<h:outputText
				value="FC Barcelona is one of only three clubs never to have been relegated from La Liga and is the most successful club in Spanish football along with Real Madrid,  
        having won twenty La Liga titles, a record twenty-five Spanish Cups, eight Spanish Super Cups, four Eva Duarte Cups and two League Cups.  
        They are also one of the most successful clubs  in European football having won fourteen official major trophies in total,  
        including ten UEFA competitions. They have won three UEFA Champions League titles, a record four UEFA Cup Winners' Cups,  
        a record three InterCities Fairs Cups (the forerunner to the UEFA Europa League), three UEFA Super Cups and one FIFA Club World Cup.  
        The club is also the only European side to have played continental football in every season since its inception in 1955." />
		</p:panel>
	</h:form>
</h:body>
</html>

e o código abaixo não renderiza o Primefaces?

<!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:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">
	<ui:define name="content">
		<h:form>
			<h3>Simple Panel</h3>
			<p:panel header="F.C. Barcelona" footer="Visca el Barca!">
				<h:outputText
					value="FC Barcelona is one of only three clubs never to have been relegated from La Liga and is the most successful club in Spanish football along with Real Madrid,  
        having won twenty La Liga titles, a record twenty-five Spanish Cups, eight Spanish Super Cups, four Eva Duarte Cups and two League Cups.  
        They are also one of the most successful clubs  in European football having won fourteen official major trophies in total,  
        including ten UEFA competitions. They have won three UEFA Champions League titles, a record four UEFA Cup Winners' Cups,  
        a record three InterCities Fairs Cups (the forerunner to the UEFA Europa League), three UEFA Super Cups and one FIFA Club World Cup.  
        The club is also the only European side to have played continental football in every season since its inception in 1955." />
			</p:panel>
		</h:form>
	</ui:define>
	<ui:define name="footer">
	    Add your footer here or delete to use the default
	</ui:define>
</ui:composition>
</html>

O que é necessário para utilizar um template? Alguma TAG ou alguma configuração no WEB.xml ?

Fico no aguardo, obrigada =)

6 Respostas

A

Há um bom tempo atras eu fiz um tutorial sobre templates, veja se te ajuda:

Hebert_Coelho

No seu template você tem um <h:head>?

Tuanny_Ramos

Olá… meu template está assim:

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
&lt;head&gt;
&lt;title&gt;&lt;ui:insert name="title"&gt;Default title&lt;/ui:insert&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

	&lt;div id="header"&gt;
		&lt;ui:insert name="header"&gt;
			&lt;ui:include src="/WEB-INF/templates/header.xhtml" /&gt;
		&lt;/ui:insert&gt;
	&lt;/div&gt;

	&lt;div id="content"&gt;
		&lt;ui:insert name="content"&gt;
		&lt;/ui:insert&gt;
	&lt;/div&gt;

	&lt;div id="footer"&gt;
		&lt;ui:insert name="footer"&gt;
		&lt;/ui:insert&gt;
	&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;
Tuanny_Ramos

Ainda não rolou =/

A

Você chegou a dar uma lida no tutorial que eu te passei tuanny?
O que está faltando no seu template é justamente a declaração do <h:head></h:head> e <h:body></h:body>
Tente reter-se a componentes do faces. Ao invés de <div id=“content”></div> utilize <h:panelGroup layout=“block” id=“content”></h:panelGroup> que será renderizado componente faces que resulta em uma div.

Tuanny_Ramos

Agora sim, entendi o funcionamento da coisa :wink:
Obrigada pela atenção.

Criado 22 de fevereiro de 2012
Ultima resposta 23 de fev. de 2012
Respostas 6
Participantes 3