Java Connector for dhtmlxGantt

We plan to release the update version of java connector in next two weeks.

If you want to try the dhtmlxGantt with java, you can download the beta version of java connector ( jar is attached to the post )

To have a working Gantt, please follow the tutorial

In steps 6 and 7, use “/data” as url for data loading and data saving.
And instead of data.php - you need to create a servlet file with code, similar to next

import java.sql.Connection;
import java.sql.DriverManager;

import com.dhtmlx.connector.*;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "JSONDataServlet", urlPatterns = {"/data"})
public class JsonGanttDataServlet extends ThreadSafeConnectorServlet{
    protected void configure(HttpServletRequest req, HttpServletResponse res) {
		Connection conn=null;
		try {
			Class.forName ("com.mysql.jdbc.Driver").newInstance ();
			conn = DriverManager.getConnection("jdbc:mysql://", "sampleDB", "sampleDB");
		} catch (Throwable e) {
		JSONGanttConnector gantt = new JSONGanttConnector(conn, DBType.MySQL);
		gantt.servlet(req, res);
		gantt.mix("open", "1");

		gantt.render_links("gantt_links", "id", "source,target,type");
		gantt.render_table("gantt_tasks", "id", "start_date,duration,text,progress,parent");

As you can see it creates and inits a JSONGanttConnector, similar to the php code in the tutorial. (302 KB)

In the desktop guide provided, it is suggested to create two tables gantt_links and gantt_tasks. But I already completed halfway my project and created tables already.

So is JSON the only way for me to conenct the gantt_tasks and tasks in DB. COuld you give me suggestions on how can I connect the project tasks with the chart for both display and update?

You can use your own tables with custom set of fields, but you need to have some fields in tasks table to store date of taks and its length, as well as related event’s id in the links table.

When using render_table command for both tasks and events you can use table names as they are in your db and data field names as they are named in your case.

So is JSON the only way for me to conenct the gantt_tasks and tasks in DB.

Thanks for your reply. If I replaced the Table “gantt_tasks” with my table, I do not have columns for duration(I have endDate column and difference between start & end date will equal to this. But which column to link?), progress. I do not want the progress feature. In this case, where do I need to tweak the js to disable the progress column and change the duration column to accept as End Date and display in DB.

If I connect the Gantt chart to DB through Java connector, do I then also load the data from JSON?. I am not getting this point.My requirement is to load the parent task and then to load the sub tasks only when the user expand the tree. Can I implement this with the current plugin?.

Thanks for your help.

If you have end_date and start_date columns that is fine as well
Try to use the code like next

conn.render_table("yourtable", "idkey", "yourstartdate(start_date), yourenddate(end_date), yourtext(text)");

here you need to replace the names of fields, but preserve values in brackets ( it instruct the connector to take the custom field from db, but process it as one of standard fields )

Yes, connector will generate json for the gantt ( you can any custom java code for the same task, connector is just one of options, it is not a mandatory requirement )

to load the sub tasks only when the user expand the tree
Not possible. Unless you are having thousands of tasks - it will cause significant effect on chart’s performance anyway.

It won’t work on Tomcat6 cause of “javax.servlet.annotation” usage.

I have tried that one with Tomcat7 and it worked to some extend (there also were some LoadXML errors while connecting task with dependency lines), however the most important issue for me is that if I try to go for Tomcat6, then I’m either having errors in lines cause of missing annotations support in Tomcat6/Dynamic Web Module 2.5:

import javax.servlet.annotation.WebServlet; @WebServlet(description = "The Gantt test", urlPatterns = { "/thegantt" })
or when I manually add the servlet-api.jar 3.0 from Tomcat7 to build path or change target back to Tomcat7, then it does compile fine in both cases (manual servlet-api 3.0 or target Tomcat7), but the gantts are not working after deployment to Tomcat6, it start, but displays empty grid/no tasks.

Please advise, how to maintain the Dynamic Web Module 2.5 compatibility in code to have it compile and running on Tomcat6 - so basically, how change the mentioned two lines in code to avoid using the annotations.


The annotations are used only in the samples, and not used in the connector library itself.
You can use connector and gantt, just remove annotations and use any other way to configure url to servlet mapping.

Hello, java connector is excellent feature.
where can I get latest java connector for dhtmlxGantt? Is it still only beta version or there are release version? Are there any samples how use it?

Top post contains a code snippet, that contains ALL java code that you need. The component is fully client side, so it requires just a single servlet for data loading and data saving.

As for connector, there was not official updates ( there was no bug reports against Java Gantt Connector as well )

Please support the MariaDB.
How that can be mapped to an MVC Controller in Spring Framework environment is also required. I connector.jar configuration is too difficult to use.

There was no official update yet, so beta version is the latest one.

Need to say - it is quite stable, there are no known issues with Java Connector and dhtmlxGantt

This is not stable, you have a new version with a fixed bug (viewtopic.php?f=15&t=40534&start=0) but that .jar doesn’t come with source code so I can’t recompile it with java6. Any solution?

In this thread viewtopic.php?f=15&t=37572 there is another jar with source code. I think you should pin that version.

Yep, I have replaced jar package in the top post with the latest one.

I am evaluating your dhtmlxGantt Java Connector. So far I got it connected to a MySQL and SqlServer environment using the methods render_table() and render_links(). This works quite well.

Now to the methods render_sql() and render_complex_sql(). As far as I understand, the Java Connector expects a table result, i.e. the output of a sql-select-statement, and will convert this into JSON by itself.

Concerning the dhtmlxGantt Java Connector I have two questions here:

Question 1) I managed to render a task table by a simple select statement as follows:

gantt.render_sql("SELECT * FROM gantt_tasks", "id", "start_date,duration,text,progress,sortorder, parent");

But how could I additionally render the corresponding links within the same chart as I did with render_table() and render_links()? Putting another statement as follows ended up with an exception:

gantt.render_sql("SELECT * FROM gantt_links", "id", "source, target, type");

Maybe I am blind, but I haven’t found a clue by reading through the documentation and form entries.

Question 2) We have a scalar sql function that already returns a valid JSON string containing a data-element for the tasks and a links-element for the links:

 {"data":[...], "collections":{"links":[...]}}

Is there a possibility to read this JSON string with one of the render_sql-methods? Not sure if we could easily refactor the sql-funktion.

Question 3) Ok, i said it was two questions and here comes number 3 :wink:
I only found your precompiled dhtmlGantt Java Connector here in the forum area. Unfortunately I could not find it at your download area. Is there some place were we could find the latest jars and/or sources even in beta stage?

Thank you in advance!

(1) Yes, there is no simple method. You can try to replace render_links with next lines

OptionsConnector links = new OptionsConnector(gantt.get_connection(), DBType.MySQL);
links.render_sql(sql, "id", "id, source, target, type");
gantt.set_options("links", links);

(2) Nope, but why do you want to use a connector in such case? You can use your own code for data loading, which will use your custom code. There is no any extra benefit in using a connector for data loading.

Yep, you can get the full sources from github -

Hello Stanislav,

thank you for your quick response!

(1) Code looked great - but had unfortunately no effect at my site. Well, I had to exhcange “gantt.get_connection()” because it seems to be private. But I already had a connection object.

Besides I found an IOException, when using the render_sql() method. Not sure where it is thrown exactly. My example code is:

protected void configure(HttpServletRequest request, HttpServletResponse response) {
// Init DB connection

// Init gantt connector
JSONGanttConnector gantt = new JSONGanttConnector(connection, DBType.MSSQL);
gantt.servlet(request, response);

// Render tasks
if (gantt.is_select_mode()) { // Code for loading data
    gantt.render_sql(SQL_SELECT_GANTT_TASKS, "id", "start_date,duration,text,progress,sortorder, parent");
} else { // Code for other operations, i.e. insert, update, delete.
    gantt.render_table("gantt_tasks", "id", "start_date,duration,text,progress,sortorder, parent");

// Render links
OptionsConnector links = new OptionsConnector(connection, DBType.MSSQL);
links.render_sql(SQL_SELECT_GANTT_LINKS, "id", "source, target, type");
gantt.set_options("links", links);

The exception already shows up without the “render links” part. Did I forget to close anything? Didn’t find such methods at JSONGanttConnector class. Stream closed
      at sun.nio.cs.StreamEncoder.ensureOpen(
      at sun.nio.cs.StreamEncoder.flush(
      at com.dhtmlx.connector.LogManager.close(
      at com.dhtmlx.connector.ThreadSafeConnectorServlet.doGet(
      at javax.servlet.http.HttpServlet.service(
      at javax.servlet.http.HttpServlet.service(
      at org.apache.catalina.core.StandardWrapper.service(
      at org.apache.catalina.core.StandardWrapperValve.invoke(
      at org.apache.catalina.core.StandardContextValve.invoke(
      at org.apache.catalina.core.StandardPipeline.doInvoke(
      at org.apache.catalina.core.StandardPipeline.invoke(
      at com.sun.enterprise.web.WebPipeline.invoke(
      at org.apache.catalina.core.StandardHostValve.invoke(
      at org.apache.catalina.connector.CoyoteAdapter.doService(
      at org.apache.catalina.connector.CoyoteAdapter.service(
      at org.glassfish.grizzly.http.server.HttpHandler.runService(
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(
      at org.glassfish.grizzly.ProcessorExecutor.execute(
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$

(2) Yes, you are right… I should take a rest sometimes to get a clearer view :wink:

(3) Thanks, I will check that out.

Does anybody have a working example in how to use dhtmlx with java (jsf), thanks in advance