Java Connector for dhtmlxGantt


#1

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
docs.dhtmlx.com/gantt/desktop__how_to_start.html

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{
	@Override
    protected void configure(HttpServletRequest req, HttpServletResponse res) {
		Connection conn=null;
		try {
			Class.forName ("com.mysql.jdbc.Driver").newInstance ();
			conn = DriverManager.getConnection("jdbc:mysql://192.168.3.251/sampleDB", "sampleDB", "sampleDB");
		} catch (Throwable e) {
			e.printStackTrace();
		}
		 
		JSONGanttConnector gantt = new JSONGanttConnector(conn, DBType.MySQL);
		gantt.servlet(req, res);
		
		gantt.mix("open", "1");
		//gantt.enable_order("sortorder");

		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.
connector.java.beta.zip (302 KB)


#2

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?


#3

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.
JSON or XML


#4

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.


#5

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.


#6

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 )


#7

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.


#8

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.

Regards,
TheUser.


#9

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.


#10

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?


#11

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 )


#12

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.


#13

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


#14

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?


#15

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


#16

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


#17

Hello,
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!


#18

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

//gantt.render_links
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.

(3)
Yep, you can get the full sources from github - github.com/DHTMLX/connector-java


#19

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:

@Override
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.

java.io.IOException: Stream closed
      at sun.nio.cs.StreamEncoder.ensureOpen(StreamEncoder.java:45)
      at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:140)
      at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
      at com.dhtmlx.connector.LogManager.close(LogManager.java:114)
      at com.dhtmlx.connector.ThreadSafeConnectorServlet.doGet(ThreadSafeConnectorServlet.java:21)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
      at java.lang.Thread.run(Thread.java:745)|#]

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

(3) Thanks, I will check that out.