Sure. Here is a sample of what I’m trying to do. Two tree components. One is the source tree I drag nodes from. The other is the target tree I drop nodes to. I want to enable custom insert, delete, update behavior on the target tree using DataProcessor.
Here is the web page:
[code]
<style type="text/css">
/*these styles allows dhtmlxLayout to work in the Full Screen mode in different browsers correctly*/
html, body {
width: 100%;
height: 100%;
margin: 0px;
overflow: hidden;
background-color:white;
}
<script type="text/javascript">
window.onload = function(){
dhtmlx.image_path='./codebase/imgs/';
var main_layout = new dhtmlXLayoutObject(document.body, '2U');
// Click-and-drag source tree.
var source_cell = main_layout.cells('a');
var source_tree = source_cell.attachTree();
source_tree.setIconsPath('./codebase/imgs/');
source_tree.enableSmartXMLParsing(true);
source_tree.enableDistributedParsing(true,100);
source_tree.enableDragAndDrop('1', true);
source_tree.setXMLAutoLoading("TheTreeConnector?prog_code=0001&is_flag=N");
source_tree.loadXML("TheTreeConnector?prog_code=0001&is_flag=N");
// Click-and-drag target tree.
var target_cell = main_layout.cells('b');
var target_tree = target_cell.attachTree();
target_tree.setIconsPath('./codebase/imgs/');
target_tree.enableSmartXMLParsing(true);
target_tree.enableDistributedParsing(true,100);
target_tree.enableDragAndDrop('1', true);
target_tree.setXMLAutoLoading("TheTreeConnector?prog_code=0005&is_flag=Y");
target_tree.loadXML("TheTreeConnector?prog_code=0005&is_flag=Y");
target_tree_DP = new dataProcessor("TheTreeConnector?prog_code=0005&is_flag=Y");
target_tree_DP.init(target_tree);
}
</script>
[/code]
The Java servlet containing the Connector code looks like this:
(I populate my tree with a Stored Procedure)
[code]package StoredProcedureServlets;
import java.sql.Connection;
import java.sql.DriverManager;
import com.dhtmlx.connector.*;
import javax.naming.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TheTreeConnector extends ThreadSafeConnectorServlet {
@Override
protected void configure(HttpServletRequest req, HttpServletResponse res) {
// Get database connection.
Connection conn = null;
String connectionURL = "";
String db_username = "";
String db_password = "";
try {
// Get application's component environment naming context.
javax.naming.Context ctx = new javax.naming.InitialContext();
javax.naming.Context env = (Context)ctx.lookup("java:comp/env");
// Get Enviroment variables from web.xml
connectionURL = (String)env.lookup("DBConnectionString");
db_username = (String)env.lookup("DBUserName");
db_password = (String)env.lookup("DBPassword");
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(connectionURL, db_username, db_password);
} catch (Throwable e) {
e.printStackTrace();
}
String prog_code;
String is_flag = "N";
// Attempt to read values from Query String parameters.
try {
prog_code = req.getParameter("prog_code");
if (req.getParameter("is_flag").equalsIgnoreCase("Y"))
is_flag = "Y";
} catch (Exception e) {
System.out.println("Missing Query String Parameter.");
}
String sql_query;
sql_query =
"SELECT * FROM TABLE(STORED_PROCEDURE_PKG.CONNECTOR_TREE_TABLE('" +
prog_code + "','" + is_flag + "')) ";
//Initialize Connector
TreeConnector treeConnector = new TreeConnector(conn, DBType.Oracle);
treeConnector.dynamic_loading(true);
// Attach Custom Tree Behaviors
treeConnector.event.attach(new TheTreeConnectorTreeItemBehavior());
treeConnector.event.attach(new TheTreeConnectorSQLBehavior(treeConnector));
// Initialization statement required for ThreadSafe Connector.
treeConnector.servlet(req, res);
treeConnector.render_sql(sql_query, "ID", "NAME", "", "PARENT_ID");
try {
conn.close();
} catch (Exception e) {
System.out.println("Closing DB exception: " + e.toString());
}
}
}[/code]
Lastly, the class that has my custom SQL behavior looks like:
[code]package StoredProcedureServlets;
import com.dhtmlx.connector.*;
public class TheTreeConnectorSQLBehavior extends ConnectorBehavior {
private TreeConnector conn;
public TheTreeConnectorSQLBehavior(TreeConnector conn) {
this.conn = conn;
System.out.println("Custom behavior constructor");
}
@Override
public void beforeInsert(DataAction action) {
System.out.println("Insert Triggered");
action.success();
}
@Override
public void beforeUpdate(DataAction action) {
System.out.println("Update Triggered");
action.success();
}
@Override
public void beforeDelete(DataAction action) {
System.out.println("Delete Triggered");
action.success();
}
}[/code]
I can see that the custom SQL behavior constructor is called, but the the beforeInsert method is not called when I drop a node on the target tree.