Jsf - date

6 respostas
anderson.bonavides
Pessoal estou com uma grande dúvida com data em JSF, não consigo utilizar datas. Esse é meu html:
<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!

6 Respostas

Lucas_Lacerda_Gertel

Faltou o conversor.

<h:inputText>
		<f:convertDateTime dateStyle="dd/MM/yyyy"/>
	</h:inputText>
anderson.bonavides

Lucas Lacerda Gertel:
Faltou o conversor.

<h:inputText> <f:convertDateTime dateStyle="dd/MM/yyyy"/> </h:inputText>

Blz e o value como ficaria?

anderson.bonavides

Desculpa Lucas viajei não prestei atenção 100%.

Obrigado…+

anderson.bonavides

Essa mensgem significa alguma coisa após a compilação?

Nome: anderson
Email: abc
Telefone: abc
Data de Nascimento: Sun Apr 29 00:00:00 BRT 1979
Nome: anderson
Email: abc
Telefone: abc
Data de Nascimento: Sun Apr 29 00:00:00 BRT 1979


15/07/2008 16:11:56 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'nome' in view.
15/07/2008 16:11:56 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'email' in view.
15/07/2008 16:11:56 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'telefone' in view.
15/07/2008 16:11:56 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'nascimento' in view.
15/07/2008 16:11:56 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'nome' in view.
15/07/2008 16:11:56 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'email' in view.
15/07/2008 16:11:56 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'telefone' in view.
15/07/2008 16:11:56 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer getForComponent
WARNING: Unable to find component with ID 'nascimento' in view.
gigicantador

No seu JSP você está setando um label "for" um inputText que não existe.
Você não setou as IDs dos inputText

#  &lt;h:outputLabel value="Email: " for="email"&gt;  
#                 &lt;f:verbatim&gt;  
#                     <br />  
#                 &lt;/f:verbatim&gt;  
#                 &lt;h:inputText value="#{contatoMB.email}" size="60" /&gt;  
#             &lt;/h:outputLabel&gt;

tem que ser

#  &lt;h:outputLabel value="Email: " for="email"&gt;  
#                 &lt;f:verbatim&gt;  
#                     <br />  
#                 &lt;/f:verbatim&gt;  
#                 &lt;h:inputText value="#{contatoMB.email}" id="email" size="60" /&gt;  
#             &lt;/h:outputLabel&gt;

Mas observe que é "só" warning.

anderson.bonavides

Hummm ok obrigado.

Funcionou…

Criado 15 de julho de 2008
Ultima resposta 15 de jul. de 2008
Respostas 6
Participantes 3