Passing date values from DateRangeSlider to Controller in Grails

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

Passing date values from DateRangeSlider to Controller in Grails

nisha.singh111
I am using jQDateRangeSlider in my GSP and I have a dropdown called 'mv' too. I am trying to pass the date values selected on dateslider into my Controller.This is how my code in GSP looks like:
<g:select from="['AFFILIATES', 'CSE','DISPLAYADS','EMAIL','MOBILEWEB','OTHERS','ORGANIC','SEO', 'SEM']" name="mv" id = "mv"
           onchange="${remoteFunction(
           controller:'Pgtyp',
           action:'ajaxGetMv',
           params:'\'mv=\' + escape(this.value)+\'&date_hour=\'+ z',
           //params:'\'mv=\'+this.value',
           onSuccess: 'printpgtyp(data)')}"
></g:select> 

</form>
<script>
dataFile = "http://localhost:8080/marchmock2/Pgtyp/datejson";

        d3.json(dataFile, function(error,data) {
        if (data)
                dataset = data;
                var min = dataset[0].a;
                var min2 = new Date(min);
                var max = dataset[dataset.length - 1].b;
                var max2 = new Date(max);
                function addZero(val) {
            if (val < 10) {
                return "0" + val;
            }  
            return val;
            }
                var s = $j("#slider").dateRangeSlider({

            bounds: {
                "min": min2,
                "max": max2
            },
            range: {
                min: {
                    hours: 1
                }
            },
            formatter:function(val){
                var m = moment(val);
                return m.format("DD/MM/YYYY HH:00:00 ");
            },
             defaultValues:{
                min: min2,
                max: max2
            }
        });
                x = (s.dateRangeSlider("values").min);
        x.setMinutes(0);
        x.setSeconds(0);
                z = x.getFullYear()+'-'+(x.getMonth()+1)+ '-'+x.getDate()+' '+x.getHours()+':'+'00'+':'+'00' ;
                var y = (s.dateRangeSlider("values").max);
        y.setMinutes(0);
        y.setSeconds(0);
         $j('#slider').on("userValuesChanged",function (e, data) {
                        var x = data.values.min;
                        x.setMinutes(0);
                        x.setSeconds(0);
                       z = x.getFullYear()+'-'+(x.getMonth()+1)+ '-'+x.getDate()+' '+x.getHours()+':'+'00'+':'+'00' ;
                        var last = data.values.max;
                        last.setMinutes(0);
                        last.setSeconds(0);
                        console.log(last)
             })
        });
This is how my controller looks like:
class PgtypController {



    def ajaxGetMv = {
        def pgtyp = Pgtyp.executeQuery("select p.date_hour,p.visits, p.mv, p.browser,p.pagetype,p.platform,p.device,p.time_period from Pgtyp p where p.mv = ? and p.date_hour= ? order by col_0_0_ asc ",[params.mv, params.date_hour])

        render pgtyp as JSON
    }

     def dataSource


        def datejson = {
        def sql = new Sql(dataSource)
        def rows = sql.rows("select min(date_hour) as a , max(date_hour) as b from pgtyp")
        sql.close()
        render rows as JSON
    }
I am getting the following error:
2014-07-16 12:07:29,538 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver  - ClassCastException occurred when processing request: [POST] /marchmock2/pgtyp/ajaxGetMv - parameters:
date_hour: 2014-6-18 10:00:00
mv: OTHERS
java.lang.String cannot be cast to java.util.Date. Stacktrace follows:
Message: java.lang.String cannot be cast to java.util.Date
    Line | Method
->>   11 | doCall    in marchmock2.PgtypController$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    200 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Where am I going wrong?