<f:view>
<h:form>
<h:panelGrid columns="1">
<h:outputLabel value="Nome: " for="nome">
<f:verbatim>
<br />
</f:verbatim>
<h:inputText value="#{contatoMB.nome}" size="60">
</h:inputText>
</h:outputLabel>
<h:outputLabel value="Email: " for="email">
<f:verbatim>
<br />
</f:verbatim>
<h:inputText value="#{contatoMB.email}" size="60" />
</h:outputLabel>
<h:outputLabel value="Telefone: " for="telefone">
<f:verbatim>
<br />
</f:verbatim>
<h:inputText value="#{contatoMB.telefone}"/>
</h:outputLabel>
<h:outputLabel value="Data de Nascimento: " for="nascimento">
<f:verbatim>
<br />
</f:verbatim>
<h:inputText value="#{contatoMB.nascimento}"/>
</h:outputLabel>
<h:commandButton action="#{contatoMB.inserirContato}" value="Salvar" />
</h:panelGrid>
</h:form>
</f:view>
MANAGED BEAN:
public class ContatoMB {
private String nome;
private String email;
private String telefone;
private Date nascimento;
public ContatoMB() {
}
public ContatoMB(String nome, String email, String telefone, Date nascimento) {
super();
this.nome = nome;
this.email = email;
this.telefone = telefone;
this.nascimento = nascimento;
}
public String getNome() {
if(this.nome == null)
this.nome = "";
return this.nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
if(this.email == null)
this.email = "";
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTelefone() {
if(this.telefone == null)
this.telefone = "";
return this.telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public Date getNascimento() {
if(this.nascimento == null)
this.nascimento = new Date();
return this.nascimento;
}
public void setNascimento(Date nascimento) {
this.nascimento = nascimento;
}
public String inserirContato(){
System.out.println("Nome: "+ this.nome);
System.out.println("Email: "+ this.email);
System.out.println("Telefone: "+ this.telefone);
System.out.println("Data de Nascimento: "+ this.nascimento);
return "teste";
}
}
RESULTADO DA COMPILAÇÃO:
15/07/2008 14:55:22 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'nome' in view.
15/07/2008 14:55:22 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'email' in view.
15/07/2008 14:55:22 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'telefone' in view.
15/07/2008 14:55:22 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'nascimento' in view.
Alguém poderia me dizer como fazer para utilizar datas?
Grato!