0
votes

I'm using eventSources method to initialize FullCalendar jQuery plugin.

eventSources: [ initEvents(visibleStartDate, visibleEndDate) ]

where initEvents is and ajax call to jsp page that returns json object representing events to be rendered. It works great but now I'd like to fetch the event only for the dates visible on calendar. I read in documentation that I could use visStart and visEnd on View object to get the start and end day of the calendar, however I don't know how to get that information at the time I initialize my eventSources. Is there a way? Thank you in advance for your responses.

Eric

1
I think I figured out my own question: The "start" and "end" parameters are added automatically by fullcalendar. More details here: arshaw.com/fullcalendar/docs/event_data/events_json_feedEric Kloc
Please post the answer, maybe other people will have the same problem in the future.nouney
In my JSP page I retrieved start date like so:String start = request.getParameter("start"); Date startDate = new Date(Long.parseLong(start)*1000); I'll post full code once I am sure it all works :)Eric Kloc
Ok but this is a comment not an answer ;)nouney
Will add full answer once 8 hour 'quarantine' for posting answers to own questions expires. Cheers, EricEric Kloc

1 Answers

0
votes

It turns out that fullcalendar plugin will add start and end HTTP parameters when calendar sources are fetched externally. Full details are described in documentation here: http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/

My code (mix of javascript, JSP, JSF):

  1. FullCalendal initialization:



page.view.calendar.fullCalendar(
{ 
....
eventSources: [ 
page.control.initEventSources(#{sessionBean.myCalendar.calendarConfgIdNbr},'Approved'),         
page.control.initCalendarHolidays(#{sessionBean.myCalendar.calendarConfgIdNbr})], 
.... 
});

var page = { 
            control : { 
                initEventSources : function(calConfId, status) {
                    return { 
                        url: '/oceportal/tom/data/bookings.jsp', 
                        type: 'POST', 
                        data: { calConfId: calConfId, bookingStatus: status, loggedInId: "#{sessionBean.loggedInId}", },
                        success: function(data) { },
                        error: function() { alert('there was an error while fetching events!'); },
                        color: 'none', 
                        textColor: page.colorConfig[status] 
                    };
                }
            }
        }
  1. My JSP snippet (to retrieve first and last visible day):

    
    String start = request.getParameter("start"); 
    Date startDt = new Date(Long.parseLong(start)*1000); 
    String end = request.getParameter("end"); 
    Date endDt = new Date(Long.parseLong(end)*1000);
    

    Hope it helps someone.