java.lang.String cannot be cast to java.util.Date

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

java.lang.String cannot be cast to java.util.Date

chichibek bros
hi group could you help me whit this scenario, im getting date values from a jqueri ui datapicker and this is my hql

def result = Request.findAll("from Request as r where r.flag = :flag and r.dateAnswer between :date1 and :date2 and r.department = :department",[flag:'completed', date1:params.date1, date2:params.date2, department:params.department])

when i added the date parameters i get this error

java.lang.ClassCastException
Message
java.lang.String cannot be cast to java.util.Date 


thanks for your help and time
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.String cannot be cast to java.util.Date

sergiomichels
Hi, maybe this topic helps you:  http://stackoverflow.com/questions/2871977/binding-a-grails-date-from-params-in-a-controller 


On Mon, Aug 27, 2012 at 12:53 PM, chichibek bros <[hidden email]> wrote:
hi group could you help me whit this scenario, im getting date values from a jqueri ui datapicker and this is my hql

def result = Request.findAll("from Request as r where r.flag = :flag and r.dateAnswer between :date1 and :date2 and r.department = :department",[flag:'completed', date1:params.date1, date2:params.date2, department:params.department])

when i added the date parameters i get this error

java.lang.ClassCastException
Message
java.lang.String cannot be cast to java.util.Date 


thanks for your help and time

Reply | Threaded
Open this post in threaded view
|

Re: java.lang.String cannot be cast to java.util.Date

nisha.singh111
Hey, did you get any solution to your problem? I have the same problem. Did the above link work for you?
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.String cannot be cast to java.util.Date

Gloria Palma
You should try :

Date from =new Date().parse("dd/MM/yyyy HH:mm:ss", params?.date1?.toString()+" 00:00:00")
Date toDate =new Date().parse("dd/MM/yyyy HH:mm:ss", params?.date2?.toString()+" 23:59:59")

def result = Request.findAll("from Request as r where r.flag = :flag and r.dateAnswer between :date1 and :date2 and r.department = :department",[flag:'completed', date1:from, date2:toDate, department:params.department])

or you can use criteria : http://grails.org/doc/2.3.9/ref/Domain%20Classes/createCriteria.html .


I am sorry for  my bad english , i am learning.