4
respostas

Um ou mais recursos possuem o destino de 'head', mas nenhum componente de 'head' foi definido na exibição.

Boa noite

Quando tento navegar na pagina livro.xhtml ocorre o seguinte erro: Um ou mais recursos possuem o destino de 'head', mas nenhum componente de 'head' foi definido na exibição.

Podem me ajudar?

livro.xtml

<?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:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <ui:composition template="_template.xhtml">
        <ui:define name="titulo">
        Novo Livro
        </ui:define>
        <ui:define name="conteudo">
            <h:form>

                <ui:define name="conteudo"></ui:define>
                <h:messages id="mensagemValidacao" />
                <fieldset>
                    <legend>Dados do Livro</legend>
                    <h:panelGrid columns="2">

                        <h:outputLabel value="Titulo:" for="titulo" />
                        <h:inputText id="titulo" value="#{livroBean.livro.titulo}"
                            required="true" requiredMessage="Título é Obrigatório"
                            validatorMessage="Título não pode ser superior a 10">
                            <f:validateLength maximum="10" />
                            <f:ajax event="blur" render="mensagemValidacao" />
                        </h:inputText>

                        <h:outputLabel value="ISBN:" for="isbn" />
                        <h:inputText id="isbn" value="#{livroBean.livro.isbn}"
                            validator="#{livroBean.meuValidadorPersonalizado}">
                            <f:ajax event="blur" render="mensagemValidacao" />

                        </h:inputText>

                        <h:outputLabel value="Preço:" for="preco" />
                        <h:inputText id="preco" value="#{livroBean.livro.preco}"
                            validatorMessage="Valor mínimo de 1 e máximo de 1000">
                            <f:validateDoubleRange minimum="1" maximum="1000" />
                        </h:inputText>

                        <h:outputLabel value="Data de Lançamento:" for="dataLancamento" />
                        <h:inputText id="dataLancamento"
                            value="#{livroBean.livro.dataLancamento.time}">
                            <f:convertDateTime pattern="dd/MM/yyyy"
                                timeZone="America/Sao_Paulo" />

                        </h:inputText>

                    </h:panelGrid>
                </fieldset>
                <fieldset>
                    <legend>Dados do Autor</legend>
                    <h:outputLabel value="Selecione Autor:" for="autor" />
                    <h:selectOneMenu id="autor" value="#{livroBean.autorId}">
                        <f:selectItems value="#{livroBean.autores}" var="autor"
                            itemLabel="#{autor.nome}" itemValue="#{autor.id}" />
                    </h:selectOneMenu>
                    <h:commandButton value="Gravar Autor"
                        action="#{livroBean.gravarAutor}">
                        <f:ajax execute="autor" render="tabelaAutor" />
                    </h:commandButton>

                    <h:dataTable value="#{livroBean.autoresDoLivro}" var="autor"
                        id="tabelaAutor">
                        <h:column>
                            <f:facet name="header">Autor</f:facet>
                            <h:outputText value="#{autor.nome}" />
                        </h:column>
                    </h:dataTable>
                    <br />
                    <h:commandLink value="Cadastrar novo autor"
                        action="#{livroBean.formAutor}" immediate="true" />
                </fieldset>
                <br />

                <h:commandButton value="Gravar" action="#{livroBean.gravar}">
                    <f:ajax execute="@form" render="@form :tabelalivros" />
                </h:commandButton>
                <br />
            </h:form>
            <fieldset>
                <legend>Lista dos Livros Cadastrados</legend>
                <h:dataTable value="#{livroBean.livros}" var="aa" id="tabelalivros">
                    <h:column>
                        <f:facet name="header">Título</f:facet>
                        <h:outputText value="#{aa.titulo}" />

                    </h:column>
                    <h:column>
                        <f:facet name="header">Preço</f:facet>
                        <h:outputText value="#{aa.preco}">
                            <f:convertNumber type="currency" pattern="R$ #,##0.00" />
                        </h:outputText>
                    </h:column>
                    <h:column>
                        <f:facet name="header">Data</f:facet>
                        <h:outputText value="#{aa.dataLancamento.time}">
                            <f:convertDateTime pattern="dd/MM/yyyy"
                                timeZone="America/Sao_Paulo" />
                        </h:outputText>
                    </h:column>
                </h:dataTable>
            </fieldset>
        </ui:define>
    </ui:composition>    

</html>

autor.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:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <ui:composition template="_template.xhtml">
        <ui:define name="titulo">
        Novo Autor
        </ui:define>
        <ui:define name="conteudo">
            <h:form>
                <fieldset>
                    <legend>Dados do Autor</legend>
                    <h:panelGrid columns="2">
                        <h:outputLabel value="Nome:" for="nome" />
                        <h:inputText id="nome" value="#{autorBean.autor.nome}"
                            required="true">
                            <f:validateLength minimum="5" />
                        </h:inputText>
                        <h:message for="nome" />
                        <h:commandButton value="Gravar" action="#{autorBean.gravar}" />
                    </h:panelGrid>
                </fieldset>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
4 respostas

_template

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"    >
<head />
<h:body>
    <div id="titulo">
        <h:graphicImage library="img" name="logo.png"/>
        <h1><ui:insert name="titulo"></ui:insert></h1>
    </div> 

    <div id="conteudo">
        <ui:insert name="conteudo"></ui:insert>
    </div> 
</h:body>

</html>

Esse erro significa que você está usando HTML simples em

em vez da tag JSF <h:head> no seu template XHTML.

Então, procure por todas as tags

<head>

</head>

e substitua-o por

<h:head>

</h:head>

Esse é o problema, não achei.

No template que você postou:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"    >
<head />
<h:body>
    <div id="titulo">
        <h:graphicImage library="img" name="logo.png"/>
        <h1><ui:insert name="titulo"></ui:insert></h1>
    </div> 

    <div id="conteudo">
        <ui:insert name="conteudo"></ui:insert>
    </div> 
</h:body>

</html>

Tem um <head /> , troca ele por

<h:head>

</h:head>

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software