Template nao esta funcionando

10 respostas
E

Pessoal,

Estou desenvolvendo o template, a minha estrutura esta no anexo
segue abaixo o meu codigo :

index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/Template.xhtml">

    <ui:define name="top">
        top
    </ui:define>

    <ui:define name="left">
        left
    </ui:define>

    <ui:define name="content">
        content
    </ui:define>

    <ui:define name="bottom">
        bottom
    </ui:define>

</ui:composition>



template.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:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="./../resources/css/default.css" rel="stylesheet" type="text/css" />
        <link href="./../resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
        <title>Facelets Template</title>
    </h:head>

    <h:body>

        <div id="top">
            <ui:insert name="top">Top</ui:insert>
        </div>
        <div>
            <div id="left">
                <ui:insert name="left">Left</ui:insert>
            </div>
            <div id="content" class="left_content">
                <ui:insert name="content">Content</ui:insert>
            </div>
        </div>
        <div id="bottom">
            <ui:insert name="bottom">Bottom</ui:insert>
        </div>

    </h:body>

</html>

quando acesso o template.xhtml aparece normalmente o layout, mas quando acesso o index.xhtml nao aparece o
layout, da a impressão que nao esta achando o template.

Alguem pode me ajudar ?

10 Respostas

CristianPalmaSola10

isso naum funciona desse jeito

template="…/template/Template.xhtml"

E

tentei fazer dessa forma

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../templates/templates.xhtml">

mas a pagina fica em branco agora

jv.nicocelli

Boa Tarde,

Eu faço da seguinte forma:

Declaro a taglib: xmlns:ui=“http://java.sun.com/jsf/facelets

// Declaração do template
&lt;ui:composition template="/templates/template.xhtml"&gt;
    &lt;ui:define name="conteudo"&gt;
       
//Aqui vai o conteúdo da página 

    &lt;/ui:define&gt;
&lt;/ui:composition&gt;
E

meu index, esta na pasta PAGE, e tentei fazer dessa forma :

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/templates/templates.xhtml">

    <ui:define name="header">
        header index
    </ui:define>

e minha pasta TEMPLATES/templates.xhtml

nao esta achando o meu template

E

Tentei fazer dessa forma, mas mesmo assim nao rolou

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/templatenovo1/web/templates/templates.xhtml">

    <ui:define name="header">
        header index
    </ui:define>
CristianPalmaSola10

Note o erro de caminho voce colocou

<ui:composition xmlns:ui=“http://java.sun.com/jsf/facelets
template="…/templates/templates.xhtml">

enquanta na imagem que voce postou a pasta do template tem o nome de template

entao o certo não seria :

&lt;ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"  
                template="../template/Template.xhtml"&gt;
E

tentei da forma , mas nao rolou .

E

anexei o projetinho …é bem pequeno , se algum poder dar uma olhada .

jv.nicocelli

Tenta colocar o diretório dessa forma:

&lt;ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"    
                template="${facesContext.externalContext.request.contextPath}/template/Template.xhtml"&gt;
L

Evandro, blza!

criei um projeto teste e não tive o problema que está relatando. Vou postar os códigos, veja se pode te ajudar vlw!

Abraços..

P.S. utilizei e mesma estrutura de diretórios mencionado, limpei e construí o projeto usando NetBeans + Glassfish e apenas executei o arquivo index.xhtml (Shift + F6)

template.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:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="./../resources/css/default.css" rel="stylesheet" type="text/css" />
        <link href="./../resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
        <title>Facelets Template</title>
    </h:head>

    <h:body>

        <div id="top">
            <ui:insert name="top">Top</ui:insert>
        </div>
        <div>
            <div id="left">
                <ui:insert name="left">Left</ui:insert>
            </div>
            <div id="content" class="left_content">
                <ui:insert name="content">Content</ui:insert>
            </div>
        </div>
        <div id="bottom">
            <ui:insert name="bottom">Bottom</ui:insert>
        </div>

    </h:body>

</html>
index.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:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <ui:composition template="../template/template.xhtml">
        <ui:define name="top">
            top
        </ui:define>

        <ui:define name="left">
            left
        </ui:define>

        <ui:define name="content">
            content
        </ui:define>

        <ui:define name="bottom">
            bottom
        </ui:define>
    </ui:composition>
</html>

e web.xml


http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

javax.faces.PROJECT_STAGE
Development


Faces Servlet
javax.faces.webapp.FacesServlet
1


Faces Servlet
/faces/*



30



faces/index.xhtml

Criado 23 de janeiro de 2013
Ultima resposta 19 de fev. de 2013
Respostas 10
Participantes 4