• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot convert 4/21/16 12:00 AM of type class java.util.Date to class java.sql.Date

 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning

I have this error (/UI/AddTask.jsp(34,5) '#{taskBean.startDate}' Cannot convert 4/21/16 12:00 AM of type class java.util.Date to class java.sql.Date )
and I'm trying to solve it by convert the data but it dose not work with me.

i have DB that save this date from the JSF and the TaskBean, can any one please see what is the problem!

TaskBean:




JSF:



Thank you.
 
Tim Holloway
Bartender
Posts: 18418
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java.util.Date and java.sql.Date are very similar classes, but they do not directly convert.

The RichFaces Calendar control requires a java.util.Date, just as radiobuttons require booleans.

It is important to remember that the JSF backing bean is a GUI Model object and not a persistence Model object. While sometimes the same object can be used in both roles, that would not be the case for dates and booleans if the persistence model isn't using java util.Date or java.lang.Boolean/boolean.

You could probably use a customer Converter to translate the backing bean property for your dates, but in your particular case, it's probably just as easy to do it this way:


And change the import on your backing bean from java.sql.Date to java.util.Date
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!