Página que não funciona o primefaces quando herdada de um template

3 respostas
Tuanny_Ramos

Olá, gostaria de tirar uma dúvida com JSF 2.0 + Primefaces 3.1.1 + Facelets.
É o seguinte:
Tenho uma página com alguns campos primefaces:

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

<h:head>
	<title>Facelet Title</title>
</h:head>
<h:body>
	<h:form id="mainForm" styleClass="mainForm" prependId="false">
		<h:panelGrid columns="1" cellpadding="5">
			<p:commandButton value="Basic" onclick="dlg1.show();" type="button" />

			<p:commandButton value="Modal" onclick="dlg2.show();" type="button" />

			<p:commandButton value="Effects" onclick="dlg3.show();" type="button" />
		</h:panelGrid>

		<p:dialog widgetVar="dlg1">
			<ui:include src="/movdiginfo.xhtml" />
		</p:dialog>

		<p:dialog header="Modal Dialog" widgetVar="dlg2" modal="true"
			height="200">
			<h:outputText value="This is a Modal Dialog." />
		</p:dialog>

		<p:dialog header="Effect Dialog" widgetVar="dlg3" showEffect="bounce"
			hideEffect="explode" height="200">
			<h:outputText value="This dialog has cool effects." />
		</p:dialog>
	</h:form>
</h:body>
</html>

e um template:

<!-- 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: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>
	<link type="text/css" rel="stylesheet"
		href="#{request.contextPath}/resources/css/fontes.css" />
	<link type="text/css" rel="stylesheet"
		href="#{request.contextPath}/resources/css/estilo.css" />
</h:head>

<h:body>

	<div id="header">
		<ui:insert name="header">
			<ui:include src="/WEB-INF/templates/header.xhtml" />
		</ui:insert>
	</div>

	<div id="content">
		<div class="centraliza1024Content">
			<div style="float: left; width: 20%;">
				<ui:insert name="menu">
					<ui:include src="/WEB-INF/templates/menu.xhtml"></ui:include>
				</ui:insert>
			</div>
			<div style="float: right; width: 80%;">
				<ui:insert name="content">
				</ui:insert>
			</div>
		</div>
	</div>

	<div id="footer">
		<ui:insert name="footer">
			<ui:include src="/WEB-INF/templates/footer.xhtml" />
		</ui:insert>
	</div>

</h:body>
</html>

SE eu herdar a pagina NewFile.xhtml desse template, meus componentes primefaces são renderizados, porém NÃO são executados, ou seja, os “dialog” não funcionam.
Alguém sabe o por quê ?

3 Respostas

L

Ola. Conseguiu resolver? Estou com um problema parecido.

Tuanny_Ramos

Então, aqui funcionou da seguinte forma:
Você deve tirar os <h:head> de todos os .xhtml que herdarão desse template e colocar todas as importações que forem utilizadas, no <h:head> do próprio template.

andii.brunetta

a estrutura da página que vai receber o template deve ser diferente:

&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
&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;ui:composition template="template.xhtml"&gt;
        &lt;ui:define name="content"&gt;
            isso é do clienteTemplate
        &lt;/ui:define&gt;
    &lt;/ui:composition&gt;
&lt;/html&gt;

Se alguém quiser entender melhor, dá uma olhada aqui:
http://javasemcafe.blogspot.com.br/2011/03/jsf-20-utilizacao-de-facelets.html

Criado 21 de março de 2012
Ultima resposta 20 de abr. de 2012
Respostas 3
Participantes 3