Error performing conversion of value ’ of type class java.lang.String to type class java.util.Date
Estou tendo este erro o que ta me tirando o sono! Estou usando JPA-Hibernate/MySQL 5 e qdo vou setar uma data usando um campo Date do MySQL a pagina me mostra isso! Vou postar um pequeno ex. que fiz para poder mostrar para vcs.
Se alguem souber o pq desde ja deixo aqui meu obrigado, sei que deve ser uma coisa boba tambem.
O bean
package br.com.meuteste.bean;
import java.util.Date;
import br.com.meuteste.persistence.Logins;
import br.com.meuteste.persistence.LoginsDAO;
public final class TesteBean extends Object {
private String password;
private String login;
private String answer;
private String email;
private String name;
private String question;
private Date dateForm;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
<gets e seters>...
public Date getDateForm() {
return dateForm;
}
public void setDateForm(Date dateForm) {
this.dateForm = dateForm;
}
public void grava() {
Logins log = new Logins(login, name, question, answer, password, email, dateForm);
LoginsDAO lDAO = new LoginsDAO();
lDAO.save(log);
}
}
Faces Config
<?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">
<managed-bean>
<managed-bean-name>testeBean</managed-bean-name>
<managed-bean-class>
br.com.meuteste.bean.TesteBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>login</property-name>
<property-class>java.lang.String</property-class>
<value></value>
</managed-property>
.
.
.
<managed-property>
<property-name>dateForm</property-name>
<property-class>java.util.Date</property-class>
<value></value>
</managed-property>
</managed-bean></faces-config>
JSP
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSF 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<f:view>
This is my JSF Test <br>
<h:form rendered="true" id="meuForm">
<br>
Login
<h:inputText value="#{testeBean.login}" rendered="true"
required="false" />
<br>
Nome
<h:inputText value="#{testeBean.name}" rendered="true"
required="true" />
<br>
Email
<h:inputText required="false" rendered="true"
value="#{testeBean.email}" />
<br>
Pergunta
<h:inputText required="false" rendered="true"
value="#{testeBean.question}" />
<br>
Resposta
<h:inputText required="false" rendered="true"
value="#{testeBean.answer}" />
<br>
Senha
<h:inputText required="false" rendered="true"
value="#{testeBean.password}" />
<br>
Data Cadastro
<h:inputText required="false" rendered="true"
value="#{testeBean.dateForm}" >
<f:convertDateTime type="date" pattern="dd-MM-yyyy" />
</h:inputText>
<br>
<br>
<br>
<h:commandButton action="#{testeBean.grava}" rendered="true"
value="Grava"></h:commandButton>
</h:form>
</f:view>
</body>
</html>
A Entity
package br.com.meuteste.persistence;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "logins", catalog = "pmesp", uniqueConstraints = {})
public class Logins implements java.io.Serializable {
// Fields
private String login;
private String name;
private String question;
private String answer;
private String password;
private String email;
private Date dateForm;
// Constructors
/** default constructor */
public Logins() {
}
/** full constructor */
public Logins(String login, String name, String question, String answer,
String password, String email, Date dateForm) {
this.login = login;
this.name = name;
this.question = question;
this.answer = answer;
this.password = password;
this.email = email;
this.dateForm = dateForm;
}
// Property accessors
@Id
@Column(name = "login", unique = true, nullable = false, insertable = true, updatable = true, length = 40)
public String getLogin() {
return this.login;
}
public void setLogin(String login) {
this.login = login;
}
@Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true, length = 40)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "question", unique = false, nullable = false, insertable = true, updatable = true, length = 40)
public String getQuestion() {
return this.question;
}
public void setQuestion(String question) {
this.question = question;
}
@Column(name = "answer", unique = false, nullable = false, insertable = true, updatable = true, length = 40)
public String getAnswer() {
return this.answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
@Column(name = "password", unique = false, nullable = false, insertable = true, updatable = true, length = 10)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "email", unique = false, nullable = false, insertable = true, updatable = true, length = 40)
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@Temporal(TemporalType.DATE)
@Column(name = "dateForm", unique = false, nullable = false, insertable = true, updatable = true, length = 10)
public Date getDateForm() {
return this.dateForm;
}
public void setDateForm(Date dateForm) {
this.dateForm = dateForm;
}
}
DDL
create table `pmesp`.`logins`(
`login` varchar(40) default '' not null,
`name` varchar(40) default '' not null,
`question` varchar(40) default '' not null,
`answer` varchar(40) default '' not null,
`password` varchar(10) default '' not null,
`email` varchar(40) default '' not null,
`dateForm` date default '' not null,
primary key (`login`)
);
create unique index `PRIMARY` on `pmesp`.`logins`(`login`);
create index `name` on `pmesp`.`logins`(`name`);
create index `email` on `pmesp`.`logins`(`email`);
create index `login_question` on `pmesp`.`logins`(`login`,`question`);
create index `email_question` on `pmesp`.`logins`(`email`,`question`);
E algo bem simples mesmo, mas nao to conseguindo nem por a pagina no ar, eu acho que isso se deve a alguma caracteristica do MySQL, algo tipo para cada parte da data como dia, mes e ano ele deve pegar separado…
O que gostaria de saber e se tem algum jeito usando o JSF de fazer isso sem ter que transformar o campo na tabela em String, mantendo ele como Date ? E como fazer isso ?
Obrigado