[RESOLVIDO]Problema Facelets JSF 2.0

4 respostas
roland

Pessoal estou com o seguinte problema:
O meu projeto usa jsf 2.0, primefaces 2.0.1 e facelets.
Quando a app inicia na página de login ta tudo blz, só que quando o usuário faz login e direciona
para outra página, o index.xhtml, esta outra página não carrega corretamente. Fica tudo meio embaralhado, e os estilos
de css não fuincionam. Tentei então carregar diretamente o index.xhtml ignorando o login e dai funcionou.
Alguém pode me ajudar? Será que é o jsf 2, ou o primefaces 2?

Este é o código:

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"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <f:view contentType="text/html">
        <h:head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <link href="./css/style.css" rel="stylesheet" type="text/css" />
        </h:head>

        <h:body>
            <div id="all">
                <ui:insert name="all">
            <div id="top">
                <ui:insert name="top">
                    <div id="top1"><span class="tituloBarra">Space Motos</span></div>
                    <div id="top2"><span class="nomeUsuario">Bem vindo: </span></div>
                    <div id="top3"><span class="nomeUsuario">faça login para entrar</span></div>
                    &lt;div id="top4"&gt;<a >Sair</a>&lt;/div&gt;
                &lt;/ui:insert&gt;
            &lt;/div&gt;

            &lt;div id="barraInfo"&gt;
                &lt;ui:insert name="barraInfo"&gt;
                    &lt;div&gt;
                        <img  />
                    &lt;/div&gt;
                    &lt;div class="texto-barra-info"&gt;
                        &lt;h1&gt;Login&lt;/h1&gt;
                    &lt;/div&gt;

                &lt;/ui:insert&gt;
            &lt;/div&gt;

            &lt;div id="menu"&gt;
                &lt;ui:insert name="menu"&gt;
                    &lt;p:menubar&gt;
                        &lt;p:submenu label="Cadastros"&gt;
                            &lt;p:submenu label="Acessórios"&gt;
                                &lt;p:menuitem label="Peças"&gt;&lt;/p:menuitem&gt;
                                &lt;p:menuitem label="Estante e Prateleiras"&gt;&lt;/p:menuitem&gt;
                            &lt;/p:submenu&gt;
                            &lt;p:menuitem label="Fornecedores" url="#"&gt;&lt;/p:menuitem&gt;
                            &lt;p:menuitem label="Funcionários" url="#"&gt;&lt;/p:menuitem&gt;
                            &lt;p:menuitem label="Clientes" url="#"&gt;&lt;/p:menuitem&gt;
                            &lt;p:menuitem label="Usuários" url="#"&gt;&lt;/p:menuitem&gt;
                        &lt;/p:submenu&gt;

                        &lt;p:submenu label="Financeiro"&gt;
                            &lt;p:menuitem label="Contas a Pagar" url="#"&gt;&lt;/p:menuitem&gt;
                            &lt;p:menuitem label="Contas a Receber" url="#"&gt;&lt;/p:menuitem&gt;
                            &lt;p:menuitem label="Plano de Contas" url="#"&gt;&lt;/p:menuitem&gt;
                        &lt;/p:submenu&gt;

                        &lt;p:submenu label="Movimentos"&gt;
                            &lt;p:menuitem label="Orçamentos" url="#"&gt;&lt;/p:menuitem&gt;
                            &lt;p:menuitem label="Ordens de Serviço" url="#"&gt;&lt;/p:menuitem&gt;
                            &lt;p:menuitem label="Vendas" url="#"&gt;&lt;/p:menuitem&gt;
                        &lt;/p:submenu&gt;

                        &lt;p:submenu label="Relatórios"&gt;
                            &lt;p:menuitem label="Index Adm" url="./Pages/Login/indexAdm.xhtml"&gt;&lt;/p:menuitem&gt;
                        &lt;/p:submenu&gt;
                    &lt;/p:menubar&gt;
                &lt;/ui:insert&gt;
            &lt;/div&gt;

            &lt;div id="content"&gt;
                &lt;ui:insert name="content"&gt;

                &lt;/ui:insert&gt;
            &lt;/div&gt;

            &lt;div id="bottom"&gt;
                &lt;ui:insert name="bottom"&gt;
                    <p >built by</p>
                    <a  >A1 Software</a>
                &lt;/ui:insert&gt;
            &lt;/div&gt;
            &lt;/ui:insert&gt;
        &lt;/div&gt;
        &lt;/h:body&gt;
    &lt;/f:view&gt;
&lt;/html&gt;

login.xhtml

&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"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"&gt;

    &lt;h:head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
        &lt;link href="./css/style.css" rel="stylesheet" type="text/css" /&gt;
    &lt;/h:head&gt;

    &lt;h:body&gt;

        &lt;ui:composition template="./../../template.xhtml"&gt;

            &lt;ui:define name="barraInfo"&gt;
                &lt;div&gt;
                    <img  />
                &lt;/div&gt;
                &lt;div class="texto-barra-info"&gt;
                    &lt;h1&gt;Login&lt;/h1&gt;
                &lt;/div&gt;
            &lt;/ui:define&gt;



            &lt;ui:define name="menu"&gt;

            &lt;/ui:define&gt;



            &lt;ui:define name="content"&gt;
                &lt;div id="coluna-unica"&gt;
                    &lt;h:form id="form-dados-user"&gt;
                        &lt;h:panelGrid columns="3"&gt;
                            &lt;f:facet name="header"&gt;
                                &lt;h:outputText value="Digite seus dados"/&gt;
                            &lt;/f:facet&gt;

                            &lt;h:outputText value="Nome:"/&gt;
                            &lt;h:inputText size="45"
                                         id="nome"
                                         value="#{usuarioC.usuario.nome}"
                                         required="true"
                                         requiredMessage="Campo Obrigatório"/&gt;
                            &lt;p:message for="nome"/&gt;

                            &lt;h:outputText value="Senha"/&gt;
                            &lt;p:password  minLength="3"
                                         maxlength="15"
                                         id="senha"
                                         value="#{usuarioC.usuario.senha}"
                                         required="true"
                                         requiredMessage="Campo Obrigatório"
                                         promptLabel="Digite uma senha segura"
                                         goodLabel="Boa"
                                         weakLabel="Razoável"
                                         strongLabel="Excelente"/&gt;
                            &lt;p:message for="senha"/&gt;
                            
                            &lt;h:selectOneMenu value="#{usuarioC.usuario.perfil}"&gt;
                                &lt;!--&lt;f:selectItem itemValue="Administrador" itemLabel="Administrador"/&gt;--&gt;
                                &lt;f:selectItem itemValue="Basico" itemLabel="Básico"/&gt;
                            &lt;/h:selectOneMenu&gt;
                        &lt;/h:panelGrid&gt;
                        &lt;h:commandButton value="Login"
                                         action="#{usuarioC.checkLogin}"/&gt;
                    &lt;/h:form&gt;
                &lt;/div&gt;
            &lt;/ui:define&gt;

        &lt;/ui:composition&gt;

    &lt;/h:body&gt;
&lt;/html&gt;

index.xhtml

&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"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"&gt;

    &lt;h:head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
        &lt;link href="./css/style.css" rel="stylesheet" type="text/css" /&gt;
    &lt;/h:head&gt;

    &lt;h:body&gt;
        &lt;f:view&gt;
        &lt;ui:composition template="./../../template.xhtml"&gt;

            
                &lt;ui:define name="top"&gt;
                    &lt;div id="top1"&gt;&lt;span class="tituloBarra"&gt;Space Motos&lt;/span&gt;&lt;/div&gt;
                    &lt;div id="top2"&gt;&lt;span class="nomeUsuario"&gt;Bem vindo: &lt;/span&gt;&lt;/div&gt;
                    &lt;div id="top3"&gt;&lt;span class="nomeUsuario"&gt;&lt;h:outputText value="#{usuarioC.session}"/&gt;&lt;/span&gt;&lt;/div&gt;
                    &lt;div id="top4"&gt;<a >Sair</a>&lt;/div&gt;
                &lt;/ui:define&gt;
            

           
                &lt;ui:define name="barraInfo"&gt;
                    &lt;div&gt;
                        <img  />
                    &lt;/div&gt;
                    &lt;div class="texto-barra-info"&gt;
                        &lt;h1&gt;Painel de Controle&lt;/h1&gt;
                    &lt;/div&gt;
                &lt;/ui:define&gt;
            

           
                &lt;ui:define name="menu"&gt;
                    &lt;h:form&gt;
                        &lt;p:menubar&gt;
                            &lt;p:submenu label="Cadastros"&gt;
                                &lt;p:submenu label="Acessórios"&gt;
                                    &lt;p:menuitem label="Peças"&gt;&lt;/p:menuitem&gt;
                                    &lt;p:menuitem label="Estante e Prateleiras"&gt;&lt;/p:menuitem&gt;
                                &lt;/p:submenu&gt;
                                &lt;p:menuitem label="Fornecedores" url="#"&gt;&lt;/p:menuitem&gt;
                                &lt;p:menuitem label="Funcionários" url="#"&gt;&lt;/p:menuitem&gt;
                                &lt;p:menuitem label="Clientes" url="#"&gt;&lt;/p:menuitem&gt;
                                &lt;p:menuitem label="Usuários" url="#"&gt;&lt;/p:menuitem&gt;
                            &lt;/p:submenu&gt;
                        &lt;/p:menubar&gt;
                    &lt;/h:form&gt;
                &lt;/ui:define&gt;
            

            
                &lt;ui:define name="content"&gt;

                &lt;/ui:define&gt;
           

        &lt;/ui:composition&gt;
&lt;/f:view&gt;
    &lt;/h:body&gt;
&lt;/html&gt;

web.xml

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app version="2.5" 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_2_5.xsd"&gt;
    &lt;context-param&gt;
        &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
        &lt;param-value&gt;Development&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
        &lt;param-name&gt;com.sun.faces.allowTextChildren&lt;/param-name&gt;
        &lt;param-value&gt;true&lt;/param-value&gt;
    &lt;/context-param&gt;

    &lt;servlet&gt;
        &lt;servlet-name&gt;Resource Servlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.primefaces.resource.ResourceServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;Resource Servlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/primefaces_resource/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;session-config&gt;
        &lt;session-timeout&gt;
            30
        &lt;/session-timeout&gt;
    &lt;/session-config&gt;
    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;faces/Pages/Login/login.xhtml&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
&lt;/web-app&gt;

4 Respostas

M

Olá Roland!

Não sei se já resolveu seu problema mas pelo que entendi… é o mesmo problema de outro post que respondi…
Veja ai se resolve seu problema…

http://www.guj.com.br/posts/list/98529.java#1064619

[]s

Manuel

roland

Blz Manuel, resolvi o meu problema. Não usei a tag de css do jsf como tu mostra no outro tópico, nem cheguei a tentar.
Mas resolvi do outro jeito e se vc não tivesse respondido o meu post não teria resolvido ainda. Vlw.

leootorres

amigo, como você resolveu o problema?

estou com um problema mais nao sei se refere ao mesmo que o seu… olhe meu post

Valeu… até maiss!
abraço

roland

Cara a resposta ta no link que o manuel.fgj posta ai.
Mas para te adiantar é isso.
Tem que usar esta linhazinha antes: #{facesContext.externalContext.requestContextPath}

&lt;link href="#{facesContext.externalContext.requestContextPath}/css/default.css" rel="stylesheet" type="text/css" /&gt;

Falow!

Criado 22 de maio de 2010
Ultima resposta 21 de mai. de 2011
Respostas 4
Participantes 3