In my JSP application for exam timetabling, I have integrated DHXScheduler and customized the lightbox to display additional information about exams using my own fields.
The EventsManager class is responsible for managing events by saving, creating, and retrieving them. It extends the DHXEventsManager class.
public class EventsManager extends DHXEventsManager {
public EventsManager(HttpServletRequest request) {
super(request);
}
public Iterable getEvents() {
Connection conn = null;
DHXEventsManager.date_format = "yyyy-MM-dd HH:mm:ss";
List<Event> events = new ArrayList<Event>();
try {
conn = SQLHelper.getConnection();
Statement statement = conn.createStatement();
StringBuffer query = new StringBuffer();
query.append("SELECT * FROM ");
query.append(TimetableEvent.TBL_EVENTS);
query.append(" e JOIN ");
query.append(StudyUnit.TBL_STUDYUNITS);
query.append(" s ON e.");
query.append(TimetableEvent.FLD_UNITCODE);
query.append(" = s.");
query.append(StudyUnit.FLD_UNITCODE);
ResultSet rs = statement.executeQuery(query.toString());
while (rs.next()) {
Event e = new Event(); // extends DHXEvent and contains additional fields
e.setId(Integer.parseInt(rs.getString(TimetableEvent.FLD_ID)));
e.setText(rs.getString(TimetableEvent.FLD_UNITCODE));
e.setStart_date(rs.getString(TimetableEvent.FLD_STARTDATE));
e.setEnd_date(rs.getString(TimetableEvent.FLD_ENDDATE));
e.setUnitCode(rs.getString(StudyUnit.FLD_UNITCODE));
e.setTitle(rs.getString(StudyUnit.FLD_TITLE));
e.setYear(rs.getString(StudyUnit.FLD_YEAR));
e.setSemester(rs.getShort(StudyUnit.FLD_SEMESTER));
e.setExamLength(rs.getFloat(StudyUnit.FLD_EXAMLENGTH));
e.setNoOfStudents(rs.getShort(StudyUnit.FLD_NOOFSTUDENTS));
e.setDepartment(rs.getString(StudyUnit.FLD_DEPARTMENT));
e.setCredits(rs.getShort(StudyUnit.FLD_CREDITS));
e.setEvening(rs.getBoolean(StudyUnit.FLD_EVENING));
events.add(e);
}
} catch (SQLException e) {
System.out.println("[EventsManager.getEvents()]: " + e.getMessage());
} finally {
SQLHelper.closeConnection(conn);
}
DHXEventsManager.date_format = "MM/dd/yyyy HH:mm";
return events;
}
@Override
public DHXStatus saveEvent(DHXEv event, DHXStatus status) {
Connection conn = SQLHelper.getConnection();
PreparedStatement pstmt = null;
ResultSet rs = null;
Event ev = (Event) event;
try {
if (status == DHXStatus.UPDATE) {
pstmt = TimetableEvent.updateEvent(conn, ev);
} else if (status == DHXStatus.INSERT) {
System.out.println("SAVE");
pstmt = TimetableEvent.insertEvent(conn, ev);
} else if (status == DHXStatus.DELETE) {
pstmt = TimetableEvent.deleteEvent(conn, event);
}
if (pstmt != null) {
pstmt.executeUpdate();
rs = pstmt.getGeneratedKeys();
if (rs.next()) {
event.setId(rs.getInt(1));
ev.setId(rs.getInt(1));
}
}
} catch (SQLException e) {
System.out.println("[EventsManager.saveEvent() - " + status.name() + "]: " + e.getMessage());
e.printStackTrace();
} finally {
if (rs != null) SQLHelper.closeResultSet(rs);
if (pstmt != null) SQLHelper.closePreparedStatement(pstmt);
if (conn != null) SQLHelper.closeConnection(conn);
}
return status;
}
@Override
public DHXEv createEvent(String id, DHXStatus status) {
return new Event();
}
}
The Event
class, which extends DHXEvent
, includes getters and setters for additional fields. However, there is an issue when casting from DHXEv
to Event
, causing the additional fields to become null since the saveEvent method only accepts DHXEv as a parameter.
Within the events.jsp
file, the getEvents() method of EventsManager is invoked to retrieve JSON objects containing events.
<%@ page contentType="application/json"
import="com.dhtmlx.planner.*,servlets.*,events.EventsManager"
%>
<%= getEvents(request) %>
<%!
String getEvents(HttpServletRequest request) throws Exception {
EventsManager evs = new EventsManager(request);
return evs.run();
}
%>
Currently, the JSON object being returned only includes fields from the DHXEv
object like
id, start_date, end_date, and text
.
{id:7, text:CIS3087, end_date:03/27/2014 13:00, start_date:03/27/2014 10:00}
I am seeking guidance on how to incorporate those additional fields into the JSON object, specifically including study unit title, department, etc.
Additionally, here is some relevant client-side code for the scheduler, including its configuration and methods such as save_form() and show_lightbox:
scheduler.config.api_date = "%Y-%m-%d %H:%i";
scheduler.config.details_on_dblclick = true;
scheduler.config.details_on_create = true;
scheduler.config.first_hour = "8";
scheduler.config.last_hour = "22";
scheduler.config.drag_lightbox = true;
scheduler.config.show_loading = true;
scheduler.config.mark_now = true;
scheduler.init('scheduler_here', new Date(), "week");
scheduler.load("events.jsp", "json");
var dp = new dataProcessor("events.jsp");
dp.init(scheduler);
function save_form() {
var ev = scheduler.getEvent(scheduler.getState().lightbox_id);
ev.text = html("studyunit_code").value;
ev.start_date = setDate("start_date", "starttime");
ev.end_date = setDate("start_date", "endtime");
scheduler.endLightbox(true, html("custom_form"));
$("#form1").submit(); // submits all the other fields and saves them to a db table
}
scheduler.showLightbox = function(id) {
var ev = scheduler.getEvent(id);
scheduler.startLightbox(id, html("custom_form"));
html("studyunit_code").value = ev.text;
html("studyunit_code").focus();
html("studyunit_title").value = ev.studyunit_title;
var startDate = ev.start_date;
getDate(startDate, "start_date", "starttime");
var endDate = ev.end_date;
getDate(endDate, "start_date", "endtime");
};
I believe a minor adjustment is required to include the fields in the JSON object and display them in the lightbox.
If you have any suggestions on resolving this issue, I would greatly appreciate it. Thank you!