Sunday, March 3, 2013

Calendar with data from database: jQuery + servlets + Ajax


I have a Java application that reads appointment data from a database and then shows them in a Java Swing UI. Now I want to publish this application online.
After a bit of research, I've found this convenient jQuery calendar and decided to use it. The main question is  then how to use my existing Java code that reads appointments and expose them to this calendar. So, what I've done:

1. created a Java servlet that reads the database







2. created the jQuery fullcalendar that invokes this servlet



Note here the "url: agenda", which basically means I'm calling the servlet deployed at /agenda.

3. then I realized that I wanted to be able to react to month/week/day changes: whenever I click the previous and next buttons, I should pass the new time period to the servlet, retrieve the new appointments from the DB and show them in the same calendar; this is how I've achieved this: