Why is the same query called 2 times? (insert problem)

Hi,

I need your help.

I use a grid, a form and a java-connector.

when I insert a new record, the new record’s color is displayed as red. (something is wrong!!)
In Oracle db, i find out that the new record is inserted correctly.
but in log file, the insert query is written twice.
so i add “debug code” in html. (beforeUpdate, afterupdate event call)

I found that the same insert query is called 2 times.
so i think that the first call is OK, but the 2nd call is not OK.

When updating, the result is the same.
I think that updating the same record again doesn’t occur an error. but it’s not normal.

Event process is like this:

  1. toolbar.onClick
  2. dp.OnBeforeUpdate: return false, so don’t call “insert query”
  3. Edit form’s field and click “submit button”
  4. Form.onButtonClick: contactForm.save()
  5. dp.OnBeforeUpdate: return true, so call “insert query” (state-inserted)
  6. Form.onButtonClick: alert(“after call…”). at this, I checked that a new record was inserted in DB .
  7. dp.OnBeforeUpdate: call again, why? I think that an error occurs here. (state-inserted)
  8. dp.onAfterUpdate: action-error
  9. dp.onAfterUpdate: action-error

log file is like this:



Client Code(html) is like this:
var contactsGrid = layout.cells(“a”).attachGrid();
contactsGrid.setHeader(“대분류,중분류,이름,비고”);
contactsGrid.setColumnIds(“DAEDIVI,JUNGDIVI,NAME,ETC”);

//form - right panel
contactForm = layout.cells(“b”).attachForm();

//saving data to server
var dpg = new dataProcessor(“/contact_manager/Etc_code_grid01_sel01”);
dpg.init(contactsGrid);
dpg.attachEvent(“onBeforeUpdate”, function(sid, state, data){
if ( state == “inserted” ){
alert(“dpg.BeforeUpdate.Inserted: sid-”+sid+“, state-”+state);
var daeDivi = contactsGrid.cells( sid, 0 ).getValue();
var jungDivi = contactsGrid.cells( sid, 1 ).getValue();
var nameD = contactsGrid.cells( sid, 2 ).getValue();

    	if( daeDivi == "" || jungDivi =="" || nameD ==""){
        	return false ;            		
    	}

    }
    else {
    	alert("dpg.BeforeUpdate.Else: sid-"+sid+", state-"+state);
    }
    return true ; 
})

dpg.attachEvent("onAfterUpdate", function(sid, action, tid, tag){
    if (action == "inserted"){
    	alert("dpg.AfterUpdate:Inserted: sid-"+sid+ ",tid-"+tid+", state-"+action); 
        contactsGrid.selectRowById(tid);  
        contactForm.setFocusOnFirstActive(); 
    }
    else {
    	alert("dpg.onAfterUpdate.Else: sid-"+sid+",tid-"+tid+", state-"+action);
    }
})

contactForm.attachEvent("onButtonClick", function(id){   
	contactForm.save();                                   
	alert("after call...");   
});

Java code(server) is like this:
((DBDataWrapper)c.sql).sequence(“SEQ_ETC_CODE.nextVal”);

((DBDataWrapper)c.sql).attach( OperationType.Insert ,“INSERT INTO SB_ETC_CODE_TEST (CODE,DAEDIVI,JUNGDIVI,DESCI,ETC) values (‘{DAEDIVI}{JUNGDIVI}’, ‘{DAEDIVI}’, ‘{JUNGDIVI}’, ‘{DESCI}’, ‘{ETC}’)”);

c.render_table(“SB_ETC_CODE_TEST”, “CODE”, “DAEDIVI,JUNGDIVI,DESCI,ETC”);

Thank you for any help.

Hi,

Please check the next two places

a) dataprocessor initialization, please be sure that dp.init line is called only once. If it is called multiple times, multiple handlers will be attached and multiple data saving calls will be triggered.

b) you have the next code line contactsGrid.selectRowById(tid); - please try to comment it. It possible that this line triggers some other code, which refreshes the form and triggers the second data saving. ( you can try to wrap this line in setTimeout call, to trigger command after end of data saving )

Thanks Stanislav every time.

but until now, it doesn’t work correctly.

  1. dp.init line is called only once.
  2. Even though I comment “contactsGrid.selectRowById(tid);”, Insert query is called twice.
    ( in case updating, it’s called twice too.)

I don’t think that “contactsGrid.SelectRowByID(tid)” occurs error.
because “contactsGrid.SelectRowByID(tid)” exist in onAfterUpdate event and Before calling the code, BeforeUpdate Event has already called twice.

I have read and have checked the DHX’s document and samples but haven’t find the cause and the solution.

Please, give some advice.

Thank you for any help.

Do you have some kind of demo which can be checked online? ( you can send me the link by PM )

Thanks for your reply!!
I sent the link (URL) by PM.

In summary,
After inserting a new record, the new record’s color in grid is red.
In AfterUpdate Event, the value of action is “error”. it shows that the server side doesn’t return a valid result.
but In DB, the new record is inserted well, and in log file, the correct sql sentence is saved.

I think that everything in DB and log is good.
but why does sever return an invalid result?

I will attach the log, the source file(java, server side) and screen-shots in form.
please, take a look on them.

Thanks for any help.

Screen-shot (grid)


screen-shot (popup, afterupdate event)

log


java

public class Etc_code_grid01_sel01 extends ThreadSafeConnectorServlet {
private static final long serialVersionUID = 1L;

@Override
protected void configure(HttpServletRequest req, HttpServletResponse res) {
	
	Connection conn= ( new DBConnection()).getConnection();				
	GridConnector c = new GridConnector(conn, DBType.Oracle);		
	c.enable_log("D:/dev/temp/tempDhmlx.log", true);
	
	c.servlet(req, res); 
	c.dynamic_loading(100); 
	
	((DBDataWrapper)c.sql).sequence("SEQ_ETC_CODE.nextVal");
	((DBDataWrapper)c.sql).attach( OperationType.Insert ,"INSERT INTO SB_ETC_CODE_TEST (CODE,DAEDIVI,JUNGDIVI,DESCI,ETC) values ('{DAEDIVI}{JUNGDIVI}', '{DAEDIVI}', '{JUNGDIVI}', '{DESCI}', '{ETC}')");
	c.render_table("SB_ETC_CODE_TEST", "CODE", "DAEDIVI,JUNGDIVI,DESCI,ETC");
	
}

}