GALERA ESTOU TENTANDO FAZER MEU PRIMEIRO EXEMPLO DE JSF E FACELETS, PORÉM ESTOU COM UM ERRO,
ACHO QUE É EM RELAÇÃO A EL JSP E EL JSF.
VOU COLOCAR TODOS OS CÓDIGOS AQUI PARA QUE VCS POSSAM DAR UM
CTRL+C / CTRL+V, NO ECLIPSE DE VCS.
Esse é o meu objeto Cadastro
public class Cadastro {
private String nome;
private String email;
private String telefone;
// gets e sets omitidos ok ?!
}
E esse é o meu bean
import br.com.itegrator.Cadastro;
public class Controle {
private Cadastro cadastro;
private List<Cadastro> cadList = new ArrayList<Cadastro>();
public Controle() {
cadastro = new Cadastro();
}
// gets e sets omitidos ok ?!
private void adicionar(Cadastro c) {
cadList.add(c);
}
public DataModel getTodos() {
return new ListDataModel(cadList);
}
public String novo() {
cadastro = new Cadastro();
return "cadastro";
}
public String salvar() {
this.adicionar(cadastro);
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage("Salvo com sucesso!");
context.addMessage(null, message);
return "cadastrados";
}
}
E os meus arquivos (x)html
Em todos esse códigos aparece uma mensagem que diz que o atributo jsfc eé indefinido
<!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="">
</ui:composition>
<head>
<title> Trabalhando com Facelets </title>
<style>
#cadastro {
margin: 0;
display: block;
position: relative;
height: auto;
float: left;
padding-bottom: 10px;
}
#cadastro fieldset {
padding-left: 25px;
border: solid #CCCCCC 1px;
margin: 0 auto;
text-align: left;
width: 350px;
padding-bottom: 25px;
}
#cadastro legend {
font-weight: bold;
font-size: 11pt;
letter-spacing: 1px;
padding-bottom: 10px;
}
html>body #cadastro legend {
margin-bottom: 0px;
}
#cadastro .field {
border-top: #333333 1px;
border-left: solid #333333 ipx;
border-bottom: solid #CCCCCC 1px;
border-right: solid #CCCCCC 1px;
font-size: 13px;
margin-bottom: 10px;
color: #0E0659;
}
#cadastro label {
display: block;
width: 80px;
float: left;
color: #000;
border-bottom: 1px solid #f1f1f1;
}
#cadastro .msg {
padding-left: 5px;
}
#cadastro fieldset {
width: 400px;
margin: 0;
padding: 5px;
}
#cadastro dd span {
padding-left: 5px;
}
</style>
</head>
<body>
<form jsfc="h:form">
<div id="cadastro">
<fieldset>
<legend>Cadastro</legend>
<label jsfc="h:outputLabel" for="nome">
Nome:
</label>
<input jsfc="h:inputText" type="text" id="nome" value="#{controle.cadastro.nome}" styleClass="field" required="true"/>
<span jsfc="h:message" for="nome"></span>
<br />
<label jsfc="h:outputLabel" for="email" >
E-mail:
</label>
<input jsfc="h:inputText" type="text" id="email" value="#{controle.cadastro.email}" styleClass="field" required="true" />
<span jsfc="h:message" for="email"></span>
<br />
<label jsfc="h:outputLabel" for="telefone">
Telefone:
</label>
<input jsfc="h:inputText" type="text" id="telefone" value="#{controle.cadastro.telefone}" styleClass="field" required="true" size="9" />
<span jsfc="h:message" for="telefone"> </span>
<br />
<br />
<input jsfc="h:commandButton" type="submit" action="#{controle.salvar}" id="confirmar" value="Salvar" />
</fieldset>
</div>
</form>
</body>
</html>
E o ultimo (x)html
<!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="">
</ui:composition>
<head>
<title>TRABALHANDO COM FACELETS</title>
<style>
.table-header {
padding: 5px;
background-color: #CCC;
color: #FFF;
}
.col-a {
}
.col-b {
background-color: #EEE;
}
</style>
</head>
<body>
<form jsfc="h:form">
<span jsfc="h:messages"></span>
<table jsfc="h:dataTable" id="tabela" value="#{controle.todos}" var="item" cellpadding="0" cellspacing="0" headerClass="table-header" columnClasses="col-a, col-b" border="1">
<tr>
<td jsfc="h:column">
<f:facet name="header">
<h:outputText value="Nome" />
</f:facet>
<h:outputText value="#{item.nome}" />
</td>
<td jsfc="h:column">
<f:facet name="header">
<h:outputText value="E-mail" />
</f:facet>
<h:outputText value="#{item.email}" />
</td>
<td jsfc="h:column">
<f:facet name="header">
<h:outputText value="Telefone" />
</f:facet>
<h:outputText value="#{item.telefone}" />
</td>
</tr>
</table>
<a jsfc="h:commandLink" action="#{controle.novo}"> Novo </a>
</form>
</body>
</html>
arquivos de configuração faces-config:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" 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_1_2.xsd">
<managed-bean>
<managed-bean-name>controle</managed-bean-name>
<managed-bean-class>br.com.itegrator.controller.Controle</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/cadastro.xhtml</from-view-id>
<navigation-case>
<from-outcome>cadastrados</from-outcome>
<to-view-id>/cadastrados.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/cadastro.xhtml</from-view-id>
<navigation-case>
<from-outcome>cadastro</from-outcome>
<to-view-id>/cadastro.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</faces-config>
e por ultimo web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<description>Facelets StarterKit</description>
<display-name>projetofacelets</display-name>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>2</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>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Depois dissso tudo tenho o seguinte erro na apresentação:
os campos inputText aparecem com a el
Nome:#{controle.cadastro.nome}
E-mail:#{controle.cadastro.email}
Telefone:#{controle.cadastro.telefone}
e o command button não me leva para a outra página - cadastrados
ná outra página - cadastrados só aparece isso:
Novo
Sem a tabela que fiz
ALGUEM PODERIA ME AJUDAR !!!