Dataprocessor "adjusting server side code" java

Hi,

The client side initialization of the dataprocessor seem straight forward. In the “adjusting server side code” section
docs.dhtmlx.com/doku.php?id=dhtm … _side_code

The following information is available
"The default package contains an example of the server side code for PHP (by additional request the similar code for JSP|ColdFusion|C#.Net|RybyOnRails can be sent). The code does the following three tasks:

a) Takes parameters from the incoming request;
b) Makes the necessary DB operation;
c) Returns the information about the operation result."

Would you please send the corresponding Java servlet /JSP code? It would be very helpful.

/Stig

For your information I am using standard edition and client side sorting.
/Stig

Try to use dhtmlxConnecto for Java. dhtmlxConnector is a set of Java classes which helps to simplify server side operations related to dhtmlx library components (dhtmlxGrid/TreeGrid, dhtmlxTree, dhtmlxCombo, dhtmlxScheduler).

Please check tutorial here docs.dhtmlx.com/doku.php?id=dhtm … orjava:toc
dhtmlx.com/docs/products/dhtmlxC … x.shtml?mn

Thank you Olga,

The basic update of a cell works now, using the Grid, Java Connector and DataProcessor on a small mysql database table.
The problem I have is that:
I have a grid with 20 columns.
The first 17 columns is from db table 1,
The 18:th column is from db table 2,
The 19:th column is from db table 1,
The 20:th column is from db table 3 (this is more complex which i will not get into now)

First I render column 1-17 using c.render_table(“shops”, “shop_id”, “shop_id, shop_name…”);
Ihave to split this up into two calls becaus one call seem to handle a maximum of 14 columns
c.render_table(“shops”, “shop_id”, “shop_id, shop_name…”); //First 14 colums
c.render_table(“shops”, “shop_id”, “daily_sales,…”); //Next 3 columns

Note that I leave out the 19:th column from table 1 because I first need to render column 18 from table 2 (for column 18 i use render_sql because i do a join between two tables to select the relevant rows to return)

Now when trying to update the cell in column 3 row 1 in the grid, i get the following error in the dataprocessor debug window:

DataProcessor
Current state
ID:1280746288218_0 Status: updated, valid


Current mode: cell
Log:
row 1280746288218_0 marked [updated,valid]
Initiating data sending for 1280746288218_0
Initiating data sending for all rows
Sending all data at once
Server url: localhost:8080/exp/conn?editing=true parameters
Server response received details
Not an XML, probably incorrect content type specified ( must be text/xml ), or some text output was started before XML data

I assume this is because I didn’t include column 19 table 1??

How can I render a grid with mixed columns like this? i.e columns from various tables are mixed, some using render_table and some render_sql and the number of columns exceeding max limit for each render method(number of arguments). Some columns cells are editable (update).

Could you please explain, I am getting this wrong.

Ihave to split this up into two calls becaus one call seem to handle a maximum of 14 columns
Actually there is no such limitation on lib. level.

How can I render a grid with mixed columns like this?
You can
a) user render_sql to load the data ( you can mix all tables in single sql query )
docs.dhtmlx.com/doku.php?id=dhtm … operations

b) use custom update logic for the saving
docs.dhtmlx.com/doku.php?id=dhtm … ex_updates

Thank you Stanislav,

The Loading works correctly now using complex sql query. But the Update doesn’t work.
I am trying to define my own sql for the update. See example below

//Load TableA and TableB
if (c.is_select_mode())
{
c.render_sql(sql, id, fields); //sql JOIN of TableB and TableA works fine
}
//Update Table A
else
{
c.sql.attach(OperationType.UPDATE, “UPDATE shops SET shop_keeper=’{shop_keeper}’ WHERE shop_id={shop_id}”;
//Update one of the columns of TableA
c.render_sql(“UPDATE shops SET shop_keeper”,“shop_id”,“shop_keeper”);
}

The sql.attach() method for the gridConnection © doesnt exist in my javaconnector. Should I include some other .jar or should I use some other method?

Thank you for your help.

Hi,

I also tried to implement custom server side event, but then “conn.sql.query()” method is not available. What am I missing?

import com.dhtmlx.connector.*;

public class UpdateBehaviour extends ConnectorBehavior 
{
  private GridConnector conn;
  public UpdateBehaviour(GridConnector conn)
  {
    this.conn = conn;
  }

  @Override
  public void beforeUpdate(DataAction data) 
  {
    String shop_keeper = data.get_value("shop_keeper");
    String shop_id = data.get_value("shop_id");
    conn.sql.query("UPDATE shops SET shop_keeper='"+shop_keeper+"' where shop_id="+shop_id);  
    data.success();
  }
  
}

AND

//Loading TableA and TableB
if (c.is_select_mode())
{
c.render_sql(sql, id, fields); //sql JOIN of TableB and TableA
}
//Update Table A
else
{
c.event.attach(new UpdateBehaviour(c));
}

Thank you

The sql.attach() method for the gridConnection © doesnt exist in my javaconnector
Cast c.sql to the DBDataWrapper type

DBDataWrapper sql = (DBDataWrapper)gridConn.sql;
        sql.attach(OperationType.UPDATE,"Update tableA set name='{name}', price={price} where id={id}");

sample code in documentation was updated
docs.dhtmlx.com/doku.php?id=dhtm … ex_updates

Thanks very much for clarifying that!

I am now casting to DBDataWrapper and can use sql.attach.query() method when implementing custom server side events.

But the beforeUpdate() method in my UpdateBehaviour Class is never triggered. i.e the sql update is never executed. I can see that sql update is not working as i enabled server side logging. In the dataprocessor logger I also receive “Server response received details
Not an XML, probably incorrect content type specified ( must be text/xml ), or some text output was started before XML data”, but sql update never sent.

I assumed the update action on the grid cell should trigger the beforeupdate() once I attach the new UpdateBehaviour event.

//attach update event to GridConnector
c.event.attach(new UpdateBehaviour(c));

UpdateBehaviour is instantiated but the beforeUpdate() method is not called. Do you have any idea what can be wrong?

Thank you

Can you provide a content of server side log , for update operation?

Also, be sure that behavior was attached before render_table or render_sql call

Only the initial data load (render_sql) is shown in the server side log. The Update sql query (in beforeUpdate() method in UpdateBehaviour class is never triggered.

Server side logfile:

Log started, Thu Aug 12 12:51:25 BST 2010

DB query
SELECT * FROM shops LEFT JOIN deals ON shops.shop_id = deals.shop_id Done in : 46ms

import com.dhtmlx.connector.*;

public class UpdateBehaviour extends ConnectorBehavior 
{
  private GridConnector conn;
  public UpdateBehaviour(GridConnector conn)
  {
    this.conn = conn;
  }

  @Override
  public void beforeUpdate(DataAction action) 
  {
    String shop_keeper = action.get_value("shop_keeper");
    String shop_id = action.get_value("shop_id");

    conn.enable_log("C:/logs/server_log.log", true);
    
    DBDataWrapper sql = (DBDataWrapper)conn.sql;
    try 
    {
      sql.query("UPDATE shops SET shop_keeper='"+shop_keeper+"' WHERE shop_id="+shop_id);  
      action.success();
    }
    catch (ConnectorOperationException e) 
    {
        e.printStackTrace(); 
    } 
  }
}

And in servlet code snippet where load and update is to be triggered

...
c.enable_log("C:/logs/server_log.log", true);

//Loading TableA and TableB
if (c.is_select_mode())
{
c.render_sql(sql, id, fields); //sql JOIN of TableB and TableA
}
//Update Table A
else
{
c.event.attach(new UpdateBehaviour(c));
}
...

Am I missing something here?

Many thanks

Hi Stanislav,

Can you see what is missing?

You can use just

c.event.attach(new UpdateBehaviour(c)); c.render_sql(sql, id, fields); //sql JOIN of TableB and TableA

in such case , for update operations you custom sql will be triggered.
you need to have some render command any way ( it configures connector, without it no any other operation will be executed )

c.is_select_mode()

Has sense if you want to use different set of fields for loading and CRUD operation, but still want them to be processed automatically.