Linha de encoding sendo exibida após navegação

2 respostas
biroska

Pessoal, estou com o seguinte problema há algum tempo:

Montei um projeto usando JSF 2.1, facelets, Netbeans 7.3 e Primefaces 3.5

Tenho um template layout.xhtml que possue 3 regiões definidas e faz o include de arquivos para elas.

Aplico o layout numa tela de login usando

<ui:composition template="/template/layout.xhtml"> <ui:define name="corpo"> ... </ui:define> </ui:composition>

Caso o usuário seja validado com sucesso ele redireciona para uma outra página, via:

Está funcionando tudo certo, mas na página redirecionada aparece no topo da página: version="1.0" encoding="UTF-8"?> que é a primeira linha do template layout.xhtml

Já deixei o arquivo de destino "teste.xhtml" igual ao de origem ("login.xhtml") e o erro persistiu.

Alguém saberia me dar alguma dica do que pode estar causando isso?

Obrigado!

2 Respostas

A

velhao coloca sua view teste.xhtml pra gente ver

biroska

Fiz alguns testes e tem haver com eu estar aplicando uma classe css no body do template.

Estou aplicando a classe: styleClass="pagina" no body do layout, senão a aplico, não ocorre o problema.

O layout tem 3 partes, topo, corpo e rodapé

No index redefino a área "corpo" do layout e no botão:
<p:commandButton type="submit" value="#{msg.botaoEntrar}" action="teste" update="panel" icon="ui-icon-person" />
disparo a ação para o arquivo teste.xhtml.

Seguem os arquivos...

[size=18]layout.xhtml[/size]

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<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"
      xmlns:p="http://primefaces.org/ui">

    <h:head><title>Teste</title></h:head>

    <h:outputStylesheet library="css" name="style.css"  />
    <h:body styleClass="pagina">  
        <p:panelGrid>  
            <p:row >
                <p:column colspan="3" >
                    <ui:insert name="cabecalho" >
                        <ui:include src="/template/topo.xhtml" />
                    </ui:insert>
                </p:column>
            </p:row>

            <p:row>
                <p:column width="22%" />
                <p:column width="56%"> 
                    <ui:insert name="corpo" >
                        <ui:include src="/template/corpo.xhtml" />
                    </ui:insert>
                </p:column>
                <p:column width="22%" />
            </p:row>

            <p:row>
                <p:column colspan="3" >
                    <ui:insert name="rodape" >
                        <ui:include src="/template/rodape.xhtml" />
                    </ui:insert>
                </p:column>
            </p:row>
        </p:panelGrid>
    </h:body>
</html>
[size=18]style.css[/size]
body.pagina{
    background-color:cadetblue;
}

table.pagina{
    horizontal-align: center;
}

fundo{
    background-color: cadetblue;
}
[size=18]topo.xhtml[/size]
<ui:fragment
    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">
  <h:form>  
      <h:graphicImage value="/resources/images/Applied_Mathematics.jpg"/>
  </h:form>
</ui:fragment>
[size=18]rodape.xhtml[/size]
<ui:fragment
    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">
  <h:form>  
        <h:commandLink action="fornecedores"/>
  </h:form>
</ui:fragment>
[size=18]index.xhtml[/size]
<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"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ui:composition template="/template/layout.xhtml">
            <ui:define name="corpo">
                <h:form id="form" >
                    <div align="center" >

                        <table style="height: 700px" width="100%">
                            <tr valign="middle" align="center">
                                <td>
                                    <p:panel id="panel" style="width: 650px;">
                                        <p:row>
                                            <p:column>
                                                <p:messages id="msgs"/>
                                            </p:column>
                                        </p:row>

                                        <p:panelGrid id="panelGrid" style="width: 534px;">

                                            <f:facet name="header">
                                                <p:row>
                                                    <p:column colspan="2">Login</p:column>
                                                </p:row>
                                            </f:facet>
                                            <p:row>
                                                <p:column>
                                                    <h:outputLabel for="usuario" value="#{msg.loginUsuario}" />  
                                                </p:column>
                                                <p:column>
                                                    <p:inputText id="usuario" label="#{msg.loginUsuario}" value="#{loginMB.usuario}" required="true" maxlength="8" size="10">
                                                        <f:validateLength minimum="2" /> 
                                                    </p:inputText>
                                                </p:column>
                                            </p:row>
                                            <p:row>
                                                <p:column>
                                                    <h:outputLabel for="senha" value="#{msg.loginPass}"/>
                                                </p:column>
                                                <p:column>
                                                    <p:password id="senha" label="#{msg.loginPass}" value="#{loginMB.senha}" required="true" maxlength="8" size="10">
                                                        <f:validateLength minimum="2" /> 
                                                    </p:password>
                                                </p:column>
                                            </p:row>

                                            <f:facet name="footer">  
                                                <p:row>
                                                    <p:column id="colunas" colspan="2" style="alignment-baseline: middle;  " >
                                                        <p:commandButton type="submit" value="#{msg.botaoEntrar}" action="teste" update="panel" icon="ui-icon-person" />  
                                                    </p:column>
                                                </p:row>
                                            </f:facet>

                                        </p:panelGrid> 
                                    </p:panel>
                                </td>
                            </tr>
                        </table>
                    </div>            
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
[size=18]teste.xhtml[/size]
<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"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ui:composition template="/template/layout.xhtml">
            <ui:define name="corpo">
                <h:form id="form" >
                    <div align="center" >

                        <table style="height: 700px" width="100%">
                            <tr valign="middle" align="center">
                                <td>
                                    Teste
                                </td>
                            </tr>
                        </table>
                    </div>            
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>

Alguma sugestão do que pode ser esse problema?

Valeu!

Criado 8 de junho de 2013
Ultima resposta 9 de jun. de 2013
Respostas 2
Participantes 2