Parsing Connector as Json

Hi,

I am pretty new to dhtmlx and the java connector and I have been following the initialization tutorial [url]https://docs.dhtmlx.com/connector__java__init.html[/url]

However when I try to do gantt.load(“BasicConnector.java”), it seems to try to parse it as json. I have included my code below:

<div id="gantt_here"
		style='width: 100%; height: 650px; position: relative;'></div>
	<script type="text/javascript">
		function createBox(sizes, class_name) {
			var box = document.createElement('div');
			box.style.cssText = [ "height:" + sizes.height + "px",
					"line-height:" + sizes.height + "px",
					"width:" + sizes.width + "px", "top:" + sizes.top + 'px',
					"left:" + sizes.left + "px", "position:absolute" ]
					.join(";");
			box.className = class_name;
			return box;
		}

		gantt.templates.grid_row_class = gantt.templates.task_class = function(
				start, end, task) {
			var css = [];
			if (gantt.hasChild(task.id)) {
				css.push("task-parent");
			}
			if (!task.$open && gantt.hasChild(task.id)) {
				css.push("task-collapsed");
			}

			return css.join(" ");
		};

		gantt.config.fit_tasks = true;
		
		gantt.init("gantt_here");

 		gantt.load("BasicConnector.java");

And this is the connector:

public class BasicConnector extends ConnectorServlet {
    @Override
    protected void configure() {
        // obtain DB connection
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/gantt", "test", "test");
        }
        catch (Throwable e) {
            e.printStackTrace();
        }

        // Initializes connector
        GridConnector gantt = new GridConnector(conn, DBType.MySQL);

        // configures the used table and fields
        gantt.render_table("gantt_tasks", "id", "start_date,duration,text,progress,parent");
    }
}

Thank you!

Hi,
i think you’re using Grid connector for gantt, which is not supposed to work (as a rule there is a connector for each component),
Please try using JSONGanttConnector instead
viewtopic.php?f=15&t=32995
github.com/DHTMLX/connector-java

Hi,

Thank you, I changed it to JSONGanttConnector and now I am getting a nullpointer exception. The request is reaching the database and the problem seems to be from the render method. Any tips?


public class BasicConnector extends ConnectorServlet {
    @Override
    protected void configure() {
        // obtain DB connection
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/gantt", "test", "test");
        }
        catch (Throwable e) {
            e.printStackTrace();
        }

        JSONGanttConnector gantt = new JSONGanttConnector(conn);
        System.out.println(gantt);
        System.out.println(conn);
        gantt.render_table("gantt_tasks", "id", "start_date,duration,text,progress,parent");
    }
}

I also tried using the dataprocessor but it doesn’t fix it.


<div id="gantt_here"
		style='width: 100%; height: 650px; position: relative;'></div>
	<script type="text/javascript">
		function createBox(sizes, class_name) {
			var box = document.createElement('div');
			box.style.cssText = [ "height:" + sizes.height + "px",
					"line-height:" + sizes.height + "px",
					"width:" + sizes.width + "px", "top:" + sizes.top + 'px',
					"left:" + sizes.left + "px", "position:absolute" ]
					.join(";");
			box.className = class_name;
			return box;
		}

		gantt.templates.grid_row_class = gantt.templates.task_class = function(
				start, end, task) {
			var css = [];
			if (gantt.hasChild(task.id)) {
				css.push("task-parent");
			}
			if (!task.$open && gantt.hasChild(task.id)) {
				css.push("task-collapsed");
			}

			return css.join(" ");
		};

		gantt.config.fit_tasks = true;
		
		gantt.init("gantt_here");

		gantt.load('/abakus/data.do');

		dp = new gantt.dataProcessor('/abakus/data.do');
		dp.init(gantt);

SEVERE: Servlet.service() for servlet dhtmlx threw exception
java.lang.NullPointerException
	at calendar.dhtmlx.connector2.JSONGanttConnector.render(JSONGanttConnector.java:190)
	at calendar.dhtmlx.connector2.BaseConnector.render_table(BaseConnector.java:330)
	at calendar.dhtmlx.connector2.BaseConnector.render_table(BaseConnector.java:295)
	at calendar.BasicConnector.configure(BasicConnector.java:41)
	at calendar.dhtmlx.connector.ConnectorServlet.doGet(ConnectorServlet.java:36)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

Hi,

I fixed the nullpointer. I was referencing some wrong files. The data is returned from the server but for some strange reason is in the wrong order. Start_date is given the value of text and so on. And duration is not even returned at all. What could be causing this?

Please be sure that you are using correct order of field names in the render command

 gantt.render_table("gantt_tasks", "id", "start_date,duration,text,progress,parent");

The must go in next order:

  • start_date
  • duration or end_date
  • text
  • any other custom parameters