Pessoal,
Comecei a estudar a versão 2 do JSF usando MyFaces. Pois bem, meu objetivo é muito simples. Criar um MB e duas páginas. Uma página contém um formulário que mandará informações para a outra exibir. Exemplo padrão para quem está começando a estudar alguma tecnologia. Só que eu estou batendo cabeça aqui e tendo um problema que não consigo identificar o que é. Por isso preciso da ajuda dos caros colegas.
Primeiramente segue informações do meu exemplo.
FuncionarioMB.java
package br.com.beans.mb;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
/**
* @author Ricardo
*
*/
@ManagedBean(name="Func")
@RequestScoped
public class FuncionarioMB implements Serializable {
private static final long serialVersionUID = 8851994468276789901L;
private String nomeCompleto;
private Integer idade;
public String getNomeCompleto() {
return nomeCompleto;
}
public void setNomeCompleto(String nomeCompleto) {
this.nomeCompleto = nomeCompleto;
}
public Integer getIdade() {
return idade;
}
public void setIdade(Integer idade) {
this.idade = idade;
}
public String cadastrar() {
return "sucesso";
}
}
helloWorld.jsp (Página com os formulários)
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Hello World</title>
</h:head>
<h:body>
<h:form id="mainForm">
<h:panelGrid columns="2">
<h:outputLabel for="name" value="Please enter your name" />
<h:inputText id="name" value="#{func.nomeCompleto}"
required="true" />
<h:outputLabel for="idade" value="Sua idade" />
<h:inputText id="idade" value="#{func.idade}" />
<h:commandButton value="Press me" action="#{Func.cadastrar}" />
<h:messages showDetail="true" showSummary="false" />
</h:panelGrid>
</h:form>
</h:body>
</html>
sucesso.jsp (vai mostrar o conteúdo da propriedade nomeCompleto)
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Insert title here</title>
</h:head>
<h:body>
<h1>Funcionou??</h1>
<h:outputText value="#{Func.nomeCompleto}"></h:outputText>
</h:body>
</html>
faces-config.xml
<?xml version="1.0"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
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_2_0.xsd">
<!-- navigation rules for helloWorld.jsp -->
<navigation-rule>
<from-view-id>/helloWorld.jsp</from-view-id>
<navigation-case>
<from-outcome>sucesso</from-outcome>
<to-view-id>/sucesso.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
web.xml
[code]<?xml version="1.0"?>
<description>MyProject web.xml</description>
<!-- Extensions Filter -->
<filter>
<filter-name>extensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<description>Set the size limit for uploaded files.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB</description>
<param-name>uploadMaxFileSize</param-name>
<param-value>100m</param-value>
</init-param>
<init-param>
<description>Set the threshold size - files
below this limit are stored in memory, files above
this limit are stored on disk.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB</description>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>*.faces</url-pattern>
</filter-mapping>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- Welcome files -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
[/code]
Estou usando Maven2 no projeto. Acredito que não seja necessário postar o POM aqui, pois aparentemente está tudo certo com relação as bibliotecas.
Empacotando minha aplicação usando mvn package, é gerado o .WAR e este war eu jogo na pasta webapps do Tomcat 6. Inicio o Tomcat normalmente. No log nenhuma excessão é disparada. O deploy da aplicação ocorre normalmente. Quando acesso a página helloWorld.jsf a página vem em branco. Se eu acessar o código fonte dessa página em branco que o tomcat cospe para mim, vem isso aqui:
[code]
<h:head>
Hello World
</h:head>
<h:body>
<h:form id=“mainForm”>
<h:panelGrid columns=“2”>
<h:outputLabel for=“name” value=“Please enter your name” />
<h:inputText id=“name” value="#{func.nomeCompleto}"
required=“true” />
<h:outputLabel for="idade" value="Sua idade" />
<h:inputText id="idade" value="#{func.idade}" />
<h:commandButton value="Press me" action="#{Func.cadastrar}" />
<h:messages showDetail="true" showSummary="false" />
</h:panelGrid>
</h:form>
</h:body>
[/code]Ou seja, parece que o Tomcat não interpreta as tags! O arquivo .WAR que é gerado está com todas as libs que preciso. Aversão do MyFaces que eu estou usando é a 2.0.0-beta2.
Alguém tem alguma noção do que pode ser isso? Ou como resolver?
Muito obrigado