Problemas de iniciante jsf Templates

7 respostas
S

Estou com um problema com templates.

segue o codigo do template:
<?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>
Segue o codigo index:
<?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="./../WEB-INF/templates/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>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/public/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>/public/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

erro:

aparece a pagina web com a seguinte msg:
"This XML file does not appear to have any style information associated with it. The document tree is shown below."
<ui:composition template="./../WEB-INF/templates/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>
Utilizando o netbeans, usando os templates basicos fornecido por ele, e nao modifiquei praticamente nada. Servidor glassfish.

vou tentar mostrar como estão posicionados os diretorios:

teste
-Web Pages
--WEB-INF
---templates
----template.xhtml
---web.xml
--public
---index.xhtml
--resources
---css
----cssLayout.css
----default.css
-Source Packages
-Libraries
-Configuration Files

7 Respostas

A

coloca fora do teu web-inf a pasta cara, se não me engano, o que esta dentro do web-inf não é visto pela view, crie uma pasta fora e de lá invoque teu template.

S

Continua com o mesmo problema :frowning:

ficou assim os diretorios:
teste
-Web Pages
–WEB-INF
—web.xml
–public
—index.xhtml
–resources
—css
----cssLayout.css
----default.css
–templates
—template.xhtml
-Source Packages
-Libraries
-Configuration Files

A

alterou o caminho na página lá? incluindo o css? e como ta a chamada no browser?

S

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>

acho que sim

S

Ta dificil, acabei de criar novamente um novo projeto e coloquei o Template e o index na mesma pasta(pasta padra), funciona normal.
É so começa a colocar em pastas distintas que da pau!
:frowning:

Coloquei a mensagem de erro:
" This XML file does not appear to have any style information associated with it. The document tree is shown below."
no google, e nada falando sobre templates com jsf

S

Acho que estou progredindo no erro!

agora nao aparece mais o erro, porem o css que esta configurado no template.xhtml, nao aparece no index.xhtml.
O que pode estar acontendo agora?( O index.xhtml aparece normal como esperado, porem o css nao )
O que modifiquei para nao aparecer o erro foi o web.xml.

ficou assim:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
   
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/public/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>
V

Sei que o topico é um pouco antigo, mas não encontrei a soluçao em nenhum lugar.

Quando tento acessar a pagina home.xhtml, só aparece o que está no template.xhtml.

Não aparece nada do que foi inserido na tag do arquivo home.xhtml

Abaixo o meu 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>
	<title>GA - Manager |:| Jv Soluções</title>
</h:head >

<h:body>
	<div id="header" style="height: 100px">
		<h1>cabeçalho</h1>
		<hr />
	</div>

	<div>
		<div style="position: absolute; top: 120px">
			<p:menu model="#{menuMb.model}"></p:menu>
		</div>

		<div style="position: absolute; top: 120px; left: 200px">			
			<ui:insert name="corpo">

			</ui:insert>
		</div>
	</div>

</h:body >
</html>

Abaixo o codigo que utiliza o template -- home.xhtml

ui:composition template="/template.xhtml"
	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:define name="corpo">
	
		<h1>TESTE</h1>
		
		<p:commandButton value="TESTE"></p:commandButton>
	</ui:define>
	
4 </ui:composition>
Criado 26 de agosto de 2011
Ultima resposta 1 de jun. de 2012
Respostas 7
Participantes 3