Página não inclui componentes jsf

8 respostas
lele_vader

Olá.Tudo bem ?
Estou tentando criar uma página jsf, porém alguns erros estão ocorrendo.
A página que eu crio não cria botões ou qualquer elemento jsf.
Se eu vejo com o firebug eles não são transformados para html, lá eu posso ver h:inputText e afins.
Somente aparecem nas páginas os labels.

Segue em anexo o faces-config e o web.xml e o layout e a página que estou tentando chamar.

web-xml

<web-app 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"
	version="3.0">

	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<!-- Servlet do jsf -->
	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<context-param>
		<param-name>javax.faces.PROJECT_STAGE</param-name>
		<param-value>Development</param-value>
	</context-param>
	<context-param>
		<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
		<param-value>.xhtml</param-value>
	</context-param>
	
	<context-param>
		<param-name>facelets.DEVELOPMENT</param-name>
		<param-value>true</param-value>
	</context-param>

	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.jsf</url-pattern>
	</servlet-mapping>
	
	<context-param>
    	<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    	<param-value>true</param-value>
	</context-param>
	
	<persistence-unit-ref>
		<persistence-unit-ref-name>persistence/CONTAS_ENTITY_MANAGER</persistence-unit-ref-name>
		<persistence-unit-name>CONTAS</persistence-unit-name>
	</persistence-unit-ref>
	
 	<!-- Referencia arquivo de propriedades das mensagens -->
 	 
 	<context-param>
		<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
		<param-value>messages.properties</param-value>
	</context-param>
</web-app>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config 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-facesconfig_1_2.xsd"
    version="1.2">
  <application>
  	<!--Configura arquivo de mensagem para validação  -->
  	<message-bundle>validacao.properties</message-bundle>
  	<resource-bundle>
  		<!-- Configura arquivo de mensagem para internacionalizacao -->
  		<base-name>messages.properties</base-name>
  		<!-- Nome da variavel a ser referenciada nas telas para mensagens  -->
  		<var>msgs</var>
  	</resource-bundle>
  	<locale-config>
  		<!-- Indica qual o locale default -->
  		<default-locale>pt_BR</default-locale>
  		<!-- Indica quais locales sao suportados -->
  		<supported-locale>en</supported-locale>
  	</locale-config>
  </application>
</faces-config>

layout.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:h="http://java.sun.com/jsf/html" 
	  xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:a4j= "http://richfaces.org/a4j"
	  xmlns:rich= "http://richfaces.org/rich">
<head>
  <title><ui:insert name="title">Programa de gerenciamento financeiro</ui:insert></title>
</head>
<body>
<div id="header">
	<h:form>
    <ui:insert name="header">
    	<!-- Cria menu dropdown -->
    	 <rich:dropDownMenu>
    	 	<f:facet name="label">
    	 		<h:outputLabel>Cadastro</h:outputLabel>
    	 	</f:facet>
    	 	<rich:menuSeparator/>
    	 	<rich:menuItem label="Categoria" action="categoria"/>
    	 </rich:dropDownMenu>
    </ui:insert>
    </h:form>
</div>
<div id="content">
  <ui:insert name="content">
  </ui:insert>
</div>
<div id="footer">
  <ui:insert name="footer">
    	Footer
  </ui:insert>
</div>
</body>
</html>

categoria.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:h="http://java.sun.com/jsf/html" 
	  xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:a4j= "http://richfaces.org/a4j"
	  xmlns:rich= "http://richfaces.org/rich">
<body>
<ui:composition template="/layout.xhtml">
	<ui:define name="content">
	    <h:form>
	    	<h:outputLabel>categoria</h:outputLabel>
	    </h:form>
	</ui:define>
</ui:composition>
</body>
</html>

inicial.xhtml (página inicial, da qual deveria aparecer o menu que está no layout)

<!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"
      xmlns:a4j= "http://richfaces.org/a4j"
	  xmlns:rich= "http://richfaces.org/rich">
<body>
<ui:composition
   template="/layout.xhtml">
	<ui:define name="content">
	   Escolha seu destino
	</ui:define>
</ui:composition>
</body>
</html>

Página inicial. Faz redirect para inicial.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"
>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<body>
	<c:redirect url="inicial.jsf"></c:redirect>
</body>
</html>

Realizei alguns testes aqui.
Pelo que vi, mesmo colocando tudo em uma página, sem layout, os elementos jsf ainda não são renderizados, por exemplo,um botão.

Muito Obrigado.

8 Respostas

F

Cara tenta o seguinte:

coloque o dentro da tag
<f:view>

Ex:

<f:view>


</f:view>

Polverini

coloque <h:head> <h:body> </h:head> </h:body>

lele_vader

Vocês recomendam colocar h:head ou f:view em quais páginas ?
A do layout ou as páginas que serão completadas por ele ?

Lembrando que as outras páginas em teoria só teriam a div do conteúdo completadas, deixando o layout com o header com o menu e o footer com alguma coisa escrita.

Obrigado.

Polverini

eu uso assim:

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:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title></title>
    </h:head>
    <h:body>
        <p:layout fullPage="true">
            <p:layoutUnit position="north" size="60">
                
            </p:layoutUnit>
            <p:layoutUnit position="center">
                <div align="center">
                    <ui:insert name="center"/>
                </div>
            </p:layoutUnit>
        </p:layout>
    </h:body>
</html>

Composite:

<?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="center">
        Pagina Inicial
    </ui:define>

</ui:composition>
lele_vader

Vou tentar quando chegar em casa.
Obrigado.

ralphsilver

lele_vader:
Vou tentar quando chegar em casa.
Obrigado.

O f:view não mata seu problema…
Como vc está utilizando jsf 2.0 … é primordial que vc troque o body e head para h:body e h:head

Se vc perceber nas páginas que ele gerou… as únicas coisas que estão faltando são os scripts que deveriam estar setados no head

lele_vader

Criei uma página sem facelets nem nada e quando mando abrir a aplicação tomo o seguinte erro.

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/learningJSF].[Faces Servlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException

Alguém poderia me mostrar o seu web.xml e o seu faces-config para eu ver como fizeram o mapeamento do faces servlet ?

Obrigado

ralphsilver

lele_vader:
Criei uma página sem facelets nem nada e quando mando abrir a aplicação tomo o seguinte erro.

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/learningJSF].[Faces Servlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException

Alguém poderia me mostrar o seu web.xml e o seu faces-config para eu ver como fizeram o mapeamento do faces servlet ?

Obrigado

O seu faces config está tudo certo… qual a versão do tomcat vc está usando?

Criado 2 de setembro de 2012
Ultima resposta 4 de set. de 2012
Respostas 8
Participantes 4