Hello,
Is it possible to customize the window used to create/update an event ?
I would like to add new textfields (name, contact, etc…). Of course, this new values must be stored in the event objet in order to be stored in the database…
Hi,
of course you may change lightbox as you want.
Here are details about configuring it:
javaplanner.com/docs/lightbox.html
I added a new Elemt in Lightbox but i am unable to get the value for it from database. I use the DHXPlanner.parse method. But since the planner take DHXEv as input its not picking up my custom field.
Hi,
you should extend DHXEv object and add public field, setter and getter for your element.
After that you should use your new event class in EventsManager to load events with additional fields.
Please, have a look at the follow tutorial, it adds several fields to events:
javaplanner.com/blog/spring-mvc- … -tutorial/
I’m trying to make a pure jsp dhtmlx schedular and I’m customizing my lightbox with new data, for example notes and client. I tried extending a new class to DHXEvent but it’s not working. Any ideas how I would be able to do this. I’m kind of a noob .
Thx
Hi,
could you provide code of classes EventsManager and Event?
Here is my EventsManager code, witch i was able to call the custom info in to the lightbox but still having trouble saving and updating the custom info.
package com.dhtmlx.bienesta;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.dhtmlx.planner.DHXEv;
import com.dhtmlx.planner.DHXEvent;
import com.dhtmlx.planner.DHXEventsManager;
import com.dhtmlx.planner.DHXStatus;
import com.mysql.jdbc.Statement;
public class EventsManager extends DHXEventsManager {
public EventsManager(HttpServletRequest request) {
super(request);
}
public Iterable getEvents() {
DHXEventsManager.date_format = "yyyy-MM-dd HH:mm:ss";
List evs = new ArrayList();
try {
java.sql.Connection conn = DatabaseConnection.getConnection();
java.sql.Statement statement = conn.createStatement();
String query = "SELECT event_id, event_name, notes, start_date, end_date FROM events";
ResultSet resultset = statement.executeQuery(query);
while (resultset.next()) {
Data e = new Data();
e.setId(Integer.parseInt(resultset.getString("event_id")));
e.setText(resultset.getString("event_name"));
e.setNotes(resultset.getString("notes"));
e.setStart_date(resultset.getString("start_date"));
e.setEnd_date(resultset.getString("end_date"));
evs.add(e);
}
conn.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
DHXEventsManager.date_format = "MM/dd/yyyy HH:mm";
return evs;
}
@Override
public DHXStatus saveEvent(DHXEv event, DHXStatus status) {
java.sql.Connection conn = DatabaseConnection.getConnection();
java.sql.PreparedStatement ps = null;
java.sql.ResultSet result = null;
try {
String query = null;
String start_date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(event.getStart_date());
String end_date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(event.getEnd_date());
if (status == DHXStatus.UPDATE) {
query = "UPDATE events SET event_name=?, notes=?, start_date=?, end_date=? WHERE event_id=?";
ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, event.getText());
ps.setString(2, notes);
ps.setString(3, start_date);
ps.setString(4, end_date);
ps.setInt(5, event.getId());
} else if (status == DHXStatus.INSERT) {
query = "INSERT INTO events (event_id, event_name, start_date, end_date) VALUES (null, ?, ?, ?)";
ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, event.getText());
ps.setString(2, start_date);
ps.setString(3, end_date);
} else if (status == DHXStatus.DELETE) {
query = "DELETE FROM events WHERE event_id=? LIMIT 1";
ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
ps.setInt(1, event.getId());
}
if (ps!=null) {
ps.executeUpdate();
result = ps.getGeneratedKeys();
if (result.next()) {
event.setId(result.getInt(1));
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (result != null) try { result.close(); } catch (SQLException e) {}
if (ps != null) try { ps.close(); } catch (SQLException e) {}
if (conn != null) try { conn.close(); } catch (SQLException e) {}
}
return status;
}
@Override
public DHXEv createEvent(String id, DHXStatus status) {
return new DHXEvent();
}
}
And here is my Data.java file
package com.dhtmlx.bienesta;
import com.dhtmlx.planner.DHXEvent;
public class Data extends DHXEvent {
public String notes;
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
}
Much appreciate your help.
Ok, got it to update and delete the events all ready inside my database with this new EventsManager code
@Override
public DHXStatus saveEvent(DHXEv event, DHXStatus status) {
java.sql.Connection conn = DatabaseConnection.getConnection();
java.sql.PreparedStatement ps = null;
java.sql.ResultSet result = null;
Data e = (Data) event;
try {
String query = null;
String start_date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(event.getStart_date());
String end_date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(event.getEnd_date());
if (status == DHXStatus.UPDATE) {
query = "UPDATE events SET event_name=?, start_date=?, end_date=?, notes=? WHERE event_id=?";
ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, event.getText());
ps.setString(2, start_date);
ps.setString(3, end_date);
ps.setString(4, e.getNotes());
ps.setInt(5, event.getId());
} else if (status == DHXStatus.INSERT) {
query = "INSERT INTO events (event_id, event_name, start_date, end_date, notes) VALUES (null, ?, ?, ?, ?)";
ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, event.getText());
ps.setString(2, start_date);
ps.setString(3, end_date);
ps.setString(4, e.getNotes());
} else if (status == DHXStatus.DELETE) {
query = "DELETE FROM events WHERE event_id=? LIMIT 1";
ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
ps.setInt(1, event.getId());
}
if (ps!=null) {
ps.executeUpdate();
result = ps.getGeneratedKeys();
if (result.next()) {
event.setId(result.getInt(1));
}
}
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
if (result != null) try { result.close(); } catch (SQLException e1) {}
if (ps != null) try { ps.close(); } catch (SQLException e1) {}
if (conn != null) try { conn.close(); } catch (SQLException e1) {}
}
return status;
}
@Override
public DHXEv createEvent(String id, DHXStatus status) {
return new Data();
}
}
But now finally I have the problem that it’s not saving my new events to my DataBase.
Is there any solution to this?
Thx
Apparently I have solved my own problem. For other people having my save problem, I solved this by modifying my main jsp file by putting the following config parameters:
s.config.setDetailsOnCreate(true);
s.config.setDblClickCreate(true);
s.config.setDetailsOnDblClick(true);
Thanks bro.