Creating a Simple Java Event Calendar

February 8, 2013

This is a detailed tutorial that covers the basic steps of creating a Java event calendar/scheduler using DHTMLX JavaPlanner library.

 

The calendar can be compiled in any preferred text editor. We have chosen Eclipse IDE to implement the task.

 

Follow the steps described in the tutorial below to create an attractive and interactive Java event calendar with intuitive drag-and-drop, seamless ajax loading and quickly set up data load and save.

java-planner

1st Creating a New Project

 

Note: to create an event calendar, you should have Apache Tomcat installed.

 

First of all, download and unzip JavaPlanner package.
Open Eclipse and create a new Dynamic web project. Let’s name it JavaPlanner.

 

2nd Adding Required Java Classes

 

2.1. Open your project folder on the disc, and copy javaplanner-v1.0.jar into WebContent/WEB-INF/lib/. The folder codebase should be copied to the WebContent folder of your project.

 

2.2. To add an external JAR, open your project Properties -> Java Build Path -> Add External Jars. Select servlet-api.jar.

 

java-build-path

 

2.3. Select Targeted Runtimes in Properties and tick Apache Tomcat.

 

2.4. Add WEB-INF/lib/scheduler.jar into build path.

 

2.5. Then create a new JSP file in the WebContent folder. Name it javaplanner.jsp. It will display the calendar in the browser.

 

javaplanner_jsp

 

It should have the following coding:

 

2.6.  Now create a new package ‘com.dhtmlx.demo’. To obtain, compile and load data to the event calendar create a new Java class ‘EventsManager’ inherited from ‘com.dhtmlx.planner.DHXEventsManager’.

 

java-class_

Modify the class code as follows:

2.7. Create a new JSP file in the WebContent folder. Name it events.jsp and replace the code:

3rd Generating the View

To run the project on the server, right-click on JavaPlanner project -> Run as -> Run on server -> Select Tomcat Server at localhost -> Finish.

java-calendar

 

Your event calendar has been created. Open your calendar in a browser: http://localhost:8080/JavaPlanner/javaplanner.jsp

 

You can drag-and-drop, delete the existing events and create new ones but they are not saved after page reload.

 

4th Setting Up the Database (MySQL)
Let’s enable loading and saving  Java calendar  events from a database.

 

4.1. First, table ‘events’ needs to be created in your database. Go to your database and create a new SQL query by adding the following code:

 

 

4.2. After the table is successfully created, copy mysql-connector-java-5.1.17-bin.jar (download) into WebContent/WEB-INF/lib/ directory from JavaPlanner Package. Add it to Build Path.

 

4.3. Go to com.dhtmlx.demo to create a new class DatabaseConnection.

Database_Connection

Add the following code:

 

4.4. Configure database connection in DatabaseConnection.java as it is shown below:

 

4.5. At this step modify EventsManager.java:

4.6. Final amendments are made to WebContent/javaplanner.jsp:


 

Refresh the project, restart the server and that’s it. Now your calendar events can be saved.

java-event-calendar

 

get-a-free-demo-now

To add more features to the created event calendar check the available documentation. There is also a two-part video that visualizes the entire tutorial.

 

Check out our other java calendar tutorials:

 

Creating a web calendar using Spring MVC

 

Creating a web calendar using Grails

 

Creating a web calendar using Struts

 

If you find this tutorial useful, you are welcome to share it with your friends. Fill free to put your comments below.

Comments (47)

  • Olya,

    Was totally stuck until I read this, now back up and runinng.

    Reply
  • Zhe Zhang,

    How can I make it both multi-resource weekly view? In each day of the week, there will be 5 columns for 5 rooms.

    Reply
    1. Dmitry,

      Hi, unfortunately there is no way to do show rooms columns in week view.

      Reply
  • udahya,

    Previously created events disappear once we create a new event. what could be the issue?

    Reply
    1. Dmitry,

      Hi,
      do you create one event, then another without reloading page?

      Reply
  • anjali,

    I am getting the following error

    java.lang.Exception: DHXScheduler trial is out-of-time.
    at com.dhtmlx.planner.DHXPlanner.check_trial(Unknown Source)
    at com.dhtmlx.planner.DHXPlanner.render(Unknown Source)
    at jsp_servlet.__javaplanner.getPlanner(__javaplanner.java:68)
    at jsp_servlet.__javaplanner._jspService(__javaplanner.java:90)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)

    Reply
  • Leon,

    I run downloaded JavaPlanner.war under Tomcat 7.0.32 and obtain next error:

    org.apache.jasper.JasperException: An exception occurred processing JSP page /javaplanner.jsp at line 12

    9: s.setInitialDate(2013, 0, 23);
    10: s.load(“events.jsp”, DHXDataFormat.JSON);
    11: s.data.dataprocessor.setURL(“events.jsp”);
    12: return s.render();
    13: }
    14: %>
    15:

    Reply
  • Juan,

    Hi.. I followed the tutorial and now I’m seeing events from my database. However, if I edit or create new events, they aren’t getting persisted. What could be the problem?

    Thanks.

    Reply
    1. administrator,

      Hi, have you completed the second part of the tutorial stating from the step 4th Setting Up the Database (MySQL)? If the problem persists, send us a link to your project.

      Reply
  • walid,

    where i most put the file of codesource

    Reply
  • Dipti,

    Is this Javaplanner compatible with Struts version 1.3?

    Reply
  • kr.vart,

    hello. Please anybody help me with javaplanner code.

    getting error on line
    public Integer saveEvent(DHXEv event, DHXStatus status) {….

    it is showing
    The return type is incompatible with DHXEventsManager.saveEvent(DHXEv,
    DHXStatus)
    what is this? I just copied it. else everything is fine here.

    Reply
  • s,

    C:\is202\JavaPlanner\src\java\com\dhtmlx\demo\EventsManager.java:50: error: saveEvent(DHXEv,DHXStatus) in EventsManager cannot override saveEvent(DHXEv,DHXStatus) in DHXEventsManager
    public Integer saveEvent(DHXEv event, DHXStatus status) {
    return type Integer is not compatible with DHXStatus
    C:\is202\JavaPlanner\src\java\com\dhtmlx\demo\EventsManager.java:49: error: method does not override or implement a method from a supertype

    getting these errors,

    Reply
  • walid,

    The EventsManager.java class won’t compile because the Integer return type for saveEvent() is incompatible with the superclass DHXEventsManager.saveEvent which is expecting DHXStatus.

    You should return status instead since JavaPlanner v1.5:

    @Override
    public DHXStatus saveEvent(DHXEv event, DHXStatus status) {

    return status;
    }

    Reply
  • maksim,

    on this line of code in EventManager.jva with MySql
    public Integer saveEvent(DHXEv event, DHXStatus status) {

    Eclipse want to change Integer and said:

    Multiple markers at this line
    - The return type is incompatible with DHXEventsManager.saveEvent(DHXEv,
    DHXStatus)
    - The return type is incompatible with DHXEventsManager.saveEvent(DHXEv,
    DHXStatus)
    - overrides com.dhtmlx.planner.DHXEventsManager.saveEvent
    - Method breakpoint:EventsManager [entry] – saveEvent(DHXEv, DHXStatus)

    Reply
  • Yogendra,

    I am not able to run project on server. getting error in console logs:

    SEVERE: A child container failed during start
    java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
    at java.util.concurrent.FutureTask.get(FutureTask.java:83)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128)
    at org

    - Deleted and added server once again.
    - Changed the port number.
    - This mainly happens when project configured to server.

    Reply
  • Biston,

    Hi I copied your project and get an error on:

    public Integer saveEvent(DHXEv event, DHXStatus status){

    return event.getid();
    }
    the error is:
    The return type is incompatible with DHXEventsManager.saveEvent(DHXEv, DHXStatus)

    Thanks

    Reply
  • administrator,

    Hi everyone!
    We’ve updated the tutorial according to the updates in javaplanner v.1.5.
    Sorry for the inconvenience.

    Reply
  • Pallavi,

    Hi Admin,

    I have followed all the steps as specified in this blog. But am using oracle as database connection to this link and trying to execute the code you have specified and steps to…. am facing problem at date format though i have used timestamp and set date format accordingly. Could you please suggest me what format i have to use when using Oracle as backend to store values.

    Reply
    1. Dmitry,

      Hi,
      please, try to set Date object without formatting:
      ps.setString(2, event.getStart_date());
      ps.setString(3, event.getEnd_date());

      Reply
  • Miloš Drinčević,

    Working fine, thank You

    Reply
  • Abdul,

    Does this only work for web applications or can I implement it into a jpane in java?

    Reply
    1. Dmitry,

      Hi, it works only for web apps.

      Reply
  • Pat,

    Hi, is it possible to limit one event per day? would be perfect for our university project than.

    thanks in advance

    Reply
  • mars,

    thank you sooo much.. that is what i exactly wanted.

    Reply
  • mars,

    please tell me where to alter the code so as to place the calendar in the middle(or customize its position according to the need) of the page.
    project works smoothly.. thanks again.

    Reply
    1. Dmitry,

      Hi,
      you should customize file javaplanner.jsp and place element with id=”planner” in the center using css or javascript. JavaPlanner doesn’t provide such ability.

      Reply
      1. mars,

        thank you so much

        Reply
  • Amao,

    Is it possible to assign only one event at any time span?It’s like one resource can only be used at one user at a time.

    Reply
    1. Dmitry,

      Hi,
      you should enable extension COLLISION:
      planner.extensions.add(DHXExtension.COLLISION);

      It denies events at the same time.

      Reply
  • Raghu,

    There is a difference in the video tutorial and the text version. Here , in the text version, the user is asked to add the scheduler.java.jar. In the video version, its not mentioned. Where can we find that Jar? The app is not working for me when I am doing everything except adding the scheduler.java.jar

    Reply
    1. Dmitry,

      Hi,
      it’s a mistake, you should add javaplanner.jar into build path instead. The article text is updated. Sorry for the inconvenience.

      Reply
  • Rafael,

    Hi to all,

    I need to display a scheduler, I’ve read and developed the examples shown in the page, however I have this error:

    [mvc-dispatcher]] (http-localhost-127.0.0.1-8080-4) Servlet.service() para servlet mvc-dispatcher lanzó excepción: java.lang.NullPointerException
    at com.dhtmlx.planner.DHXEventsManager.load(DHXEventsManager.java:53) [javaplanner-1.5.jar:]
    at com.dhtmlx.planner.DHXEventsManager.run(DHXEventsManager.java:42) [javaplanner-1.5.jar:]

    I use JBoss 7.1, Spring 3.2.8 and this is part of my code in my controller class

    @RequestMapping(“/myplanner”)
    public ModelAndView planner(HttpServletRequest request) throws Exception {
    DHXPlanner p = new DHXPlanner(“./codebase/”, DHXSkin.TERRACE);
    p.setInitialDate(2013, 1, 7);
    p.config.setScrollHour(music);
    p.setWidth(900);
    p.load(“events”, DHXDataFormat.JSON);

    ModelAndView mnv = new ModelAndView(“article”);
    mnv.addObject(“body”, p.render());
    return mnv;
    }

    @RequestMapping(“/events**”)
    @ResponseBody public String events(HttpServletRequest request) {

    CustomEventsManager evs = new CustomEventsManager(request);
    //evs.getEvents();
    return evs.run();
    }

    I hope someone can help to solve this. Thanks.

    BR

    Reply
    1. Dmitry,

      Hi,
      sorry for the delay in answerring.
      It looks like you missed something in step 2.6.
      Method CustomEventsManager.getEvents returns null instead of list of events for some reasons .
      Please, make sure that signature of method getEvents is the same as here:

      public Iterable getEvents()

      Reply
  • RD,

    public Integer saveEvent(DHXEv event, DHXStatus status) {
    |
    |
    |
    return event.getId();
    }

    I keep getting this error. “The return type is incompatible with DHXEventsManager.saveEvent(DHXEv, DHXStatus)

    I’ll appreciate it, if anyone could help.

    Reply
    1. Dmitry,

      Please, update your code of EventsManager.java according the follow:

      public DHXStatus saveEvent(DHXEv event, DHXStatus status) {
      ….
      return status;
      }

      Reply
  • frank,

    I’ve copied this tutorial word for word and followed the video tutorial. MY database is connecting to the app and so’s the data (through debugging) but my table data isn’t being displayed on my calendar.

    Reply
    1. frank,

      resolved.. sorry, my events.jsp page had other HTML tags in it and was breaking things. Everything is in order now. However i would love to get my hands on the javadoc documentation for intellisense of my eclipse. Can you guys help me out with that?

      Reply
      1. Dmitry,

        Hi,
        unfotunately we don’t provide javadoc documentation for intellisense.

        Reply
  • KAILASH,

    Dear Admin,
    I have followed the mentioned steps. I am using NetBeans IDE. However when i run the application, it shows me blank JSP. I checked in all browsers. In Firefox even i checked using Inspect Element. It is not showing any error.

    Could you please tell me the possible cause for this ?

    Regards,
    Kailash

    Reply
    1. Andres,

      Hi Admin,
      I am having the same issue as Kailash; I browse to http://localhost:8080/JavaPlanner/javaplanner.jsp and am getting a blank page. If I view source I see some HTML but it looks like the references to ./codebasedhtmlxscheduler.js and ./codebase/dhtmlxscheduler.css are broken.

      Reply
      1. Andres,

        Found a work around –
        I downloaded http://www.dhtmlx.com/x/download/regular/dhtmlxScheduler.zip

        I grabbed the 2 missing files and dropped them in to the WebContent folder in the eclipse project.

        I updated javaplanner.jsp and changed the line:
        DHXPlanner s = new DHXPlanner(“./codebase/”, DHXSkin.TERRACE);

        to:
        DHXPlanner s = new DHXPlanner(“”, DHXSkin.TERRACE);

        There may be a better solution but I am in a hurry here trying to evaluate some options for our product.
        Just thought I’d share my solution in case some one else runs in to the same issue.

        Reply
  • Dmitry,

    Hi guys.
    It looks like javascript/css files are missed on your web-server. Please, make sure that you made step 2.1 correctly. Please, try to update your project to make your IDE “see” this directory:

    2.1. Open your project folder on the disc, and copy javaplanner-v1.0.jar into WebContent/WEB-INF/lib/. The folder codebase should be copied to the WebContent folder of your project.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

three × = 6

You may use these HTML tags and attributes:
<b></b> <i></i> <strike></strike> <a href=""></a>