views:

162

answers:

3

I'm trying to display a jQuery FullCalendar (http://arshaw.com/fullcalendar) inside a Grails GSP and to populate it from a controller. Here is the Javascript code to initialize my calendar:

$('#container').fullCalendar({
  header: {
      left: 'prev,next today',
      center: 'title',
      right: 'month,agendaWeek,agendaDay'
  },
  editable: false,
  firstDay: 1,
  events: '${createLink(controller: "myEvent", action: "events")}'

});

And my controller returns the following JSON (curtesy of Firebug):

[{"id":"1","title":"Devoxx 2010","allDay":true,"start":new Date(1289775600000),"end":new Date(1290121200000),"url":"http://www.devoxx.com"}]

And the problem is that I don't see anything appear in the calendar although I'm on the right month. No event is displayed and I don't get any errors. Any idea what may be missing?

A: 

${...} does not look correct in jquery to return a function, just the function or $(...)

Sebastien Plisson
@Sebastien that is groovy code... not jQuery, the ${} is correct
Aaron Saunders
A: 

If firebug is returning that exact string as you have it, it's not going to work because of the new Date() functions. The dates should already be a date. Not a function to create a date. For example, my json looks like the following:

[{"id":"Board_Meeting_0","title":"Board Meeting","start":"Fri, 20 Aug 2010 14:00:00 CDT","end":"Fri, 20 Aug 2010 15:00:00 CDT","allDay":false}]
Gregg
Yay, it works great now! Thanks a lot! In fact, fulllcalendar's documentation is a little misleading because it says start and end should be Date instances, not Strings, but then when you read the description it says it's a String. Anyways, to avoid having a String and have a Date Object instead, I had added the following parameter to my Grails config: grails.converters.json.date = 'javascript' All I had to do was to remove it or set it to grails.converters.json.date = 'default'. And now it works... almost. My events appear but the days are shifted. But I'll figure out that one. Thanks again!
Sebastien
A: 

Hi all,

I am having a similar problem. I am creating a JSON array in my servlet and am setting that as a request parameter. When I fetch this in my JSP my string looks like this:

My Javascri[pt is as given below:

        $(document).ready(function() {

        if (!this.JSON) {
            this.JSON = {};
        }


        alert($('#sampleData').val());

         $('#mycalendar').fullCalendar({
                // put your options and callbacks here
                header: {
        left: 'prevYear,prev,next,nextYear today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    editable: true,
                events: JSON.parse($('#sampleData').val())


    });

My alert prints:

[{"title":"json event test1","start":"25/20/2010","end":"25/22/2010"},{"title":"json event test2","start":"25/20/2010","end":"25/26/2010"}]

My Servlet does this:

 SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");

    JSONObject testObj1 = new JSONObject();
    testObj1.put("title", "json event test1");
    testObj1.put("start", sdf.format(today));
    testObj1.put("end", sdf.format(end));

    JSONObject testObj2 = new JSONObject();
    testObj2.put("title", "json event test2");
    testObj2.put("start", sdf.format(today));
    testObj2.put("end", sdf.format(end2));

    JSONArray eventsArray = new JSONArray();
    eventsArray.add(testObj1);
    eventsArray.add(testObj2);

    resp.sendRedirect("jsp/MyCalendarJsp.jsp?events="+eventsArray.toString());

Could you please let me know what is wrong?

shruthi
It was a stupid error!! The value of month is invalid. That's the reason why it is not working! Sorry for the stupid question!!
shruthi