DayPilot Pro for Java 7.9 SP1

Release date: November 26, 2014 (build 7.9.8349)

Recurrence Support (Calendar, Month, Scheduler)

java scheduler recurrring events jsp j2ee

Creating a new rule using RecurrenceRule class

import org.daypilot.recurrence.RecurrenceRule;


String id = "123"; // id of the master event
DateTime start = new DateTime("2014-11-26T10:00:00");  // start of the master event

RecurrenceRule rule = RecurrenceRule.fromDateTime(id, start).daily().indefinitely();
String recurrence = rule.encode();

This string should be stored in the database in a special VARCHAR field (e.g. "event_recurrence").

Loading recurrence data

Specify the data source field with recurrence data using setDataRecurrenceField():

setDataResourceField("event_resource");
setDataIdField("event_id");
setDataTextField("event_name");
setDataStartField("event_start");
setDataEndField("event_end");

setDataRecurrenceField("event_recurrence");

Creating a new exception (delete a specific occurrence)

Create a new database record and store the following recurrence string in the recurrence field:

String masterId = "123";  // id of the master event
DateTime start = new DateTime("2014-11-27T10:00:00");

String recurrence = RecurrenceRule.encodeExceptionModified(masterId, start);

Create a new exception (modify a specific occurrence)

Create a new database record and store the following recurrence string in the recurrence field:

String masterId = "123";  // id of the master event
DateTime start = new DateTime("2014-11-27T10:00:00");

String recurrence = RecurrenceRule.encodeExceptionModified(masterId, start);

The values from the regular fields (start, end, text, etc.) will be used for this occurrence.

Custom storage mechanism

You can build the recurrence rule manually instead of using the built-in recurrence rule encoding mechanism.

  1. Don't specify dataRecurrenceField property
  2. Handle onBeforeEventRecurrence event and build RecurrenceRule manually from the record.
  3. Save it in rule property of the event argument class
public void onBeforeEventRecurrence(BeforeEventRecurrenceArgs a) {
  Event e = a.getEvent();
  Object source = e.getSource();
  
  RecurrenceRule rule = ...
  a.setRule(rule);
}

Manually expanding the occurrences

You can use RecurrenceExpander class to get a list of expanded occurrences. You need to supply the data source in the same format as used for DayPilotScheduler.events property:

RecurrenceExpander rex = new RecurrenceExpander();
rex.setDataResourceField("event_resource");
rex.setDataIdField("event_id");
rex.setDataTextField("event_name");
rex.setDataStartField("event_start");
rex.setDataEndField("event_end");
rex.setDataRecurrenceField("event_recurrence");
rex.setEvents(...);   // Collection<?>

DateTime rangeStart  = new DateTime("2014-11-01T00:00:00");  // start of the result range
DateTime rangeEnd = new DateTime("2014-11-30T00:00:00");  // end of the result range
TimeSpan maxChange = TimeSpan.fromDays(14);   // maximum allowed shift of the original occurrence modification (in backward direction)
List<Event> result = rex.expand(rangeStart, rangeEnd, maxChange);

The supplied data source can include regular events.

It should include all records that have data in the recurrence field:

  • from anywhere in the past (even before rangeStart); this is to make sure that all rules are included
  • up to rangeEnd plus maxChange; this is to make sure that all relevant exceptions are included

Detecting recurring events in event handlers

All event handlers (server-side and client-side) store information about event recurrence.

Server-side events:

  • args.isRecurrent() - true for events that are part of the recurrence series
  • args.getRecurrentMasterId() - reference to the master event id

Client-side events:

  • args.recurrent()
  • args.recurrentMasterId()

For the regular occurrences args.getId() will return null.

For exceptions (deleted and modified occurrences) args.getId() will return the exception record id.