Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    CellClickEvent.getRecord JS null error

    Hello,

    event.getRecord() throws a nasty JS error when you have editValues in a grid (because of a validation error).

    Repro:
    click the Add new record button
    Fill in 50 in column0
    Go out of edit mode
    Click the row


    Code:
    private class MyType extends SimpleType {
    	public MyType() {
    		super("mine", FieldType.ANY);
    		
    		IntegerRangeValidator v = new IntegerRangeValidator();
    		v.setMin(1);
    		v.setMax(10);
    		setValidators(v);
    	}
    }
    
    private void test16() {
    	Canvas c = new Canvas();
    	c.setBorder("20px solid black");
    	c.setWidth(500);
    	c.setHeight(200);
    	
    	new MyType().register();
    	
    	final ListGrid grid = new ListGrid();
    	grid.addCellClickHandler(new CellClickHandler() {
    		
    		public void onCellClick(CellClickEvent event) {
    			GWT.log("SilkListGrid on cell click");
    			ListGridRecord r = event.getRecord();
    		}
    	});
    	grid.setWidth(200);
    	grid.setHeight(200);
    	String fieldName1 = "a";
    	String fieldName2 = "b";
    	ListGridField field1 = new ListGridField(fieldName1);
    	field1.setAttribute("type", "mine");
    	ListGridField field2 = new ListGridField(fieldName2);
    	grid.setFields(field1, field2);
    	
    	Button addData = new Button("Add new record");
    	addData.addClickHandler(new ClickHandler() {
    		
    		public void onClick(ClickEvent event) {
    			Record newRecordDefaults = new Record();
    			grid.startEditingNew(newRecordDefaults);
    		}
    	});
    	
    	VLayout layout = new VLayout();
    	layout.setWidth100();
    	layout.setHeight(600);
    	layout.setMembers(c, addData, grid);
    	masterPanel.addChild(layout);
    }
    Code:
    Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError): elem is null
     fileName: http://localhost:8880
     lineNumber: 56
     stack: (null,"__ref")@http://localhost:8880:56
    (null,5767386,null)@http://localhost:8880/smarteetester/hosted.html?smarteetester:56
    ()@http://localhost:8880:19
    ([object GWTJavaObject],1179847,[object GWTJavaObject])@http://localhost:8880/smarteetester/hosted.html?smarteetester:56
    (null,0,1)@http://localhost:8880:1876
    ((function () {var param = {record: arguments[0], rowNum: arguments[1], colNum: arguments[2]};var event = __gwt_makeJavaInvoke(1)(null, 10944643, param);__gwt_makeJavaInvoke(1)(selfJ, 1179847, event);var ret = __gwt_makeJavaInvoke(0)(event, 1572870);return !ret;}),[object Object],[object Arguments])@http://localhost:8880:77
    (null,94,(function () {var param = {record: arguments[0], rowNum: arguments[1], colNum: arguments[2]};var event = __gwt_makeJavaInvoke(1)(null, 10944643, param);__gwt_makeJavaInvoke(1)(selfJ, 1179847, event);var ret = __gwt_makeJavaInvoke(0)(event, 1572870);return !ret;}),[object Object],[object Arguments])@http://localhost:8880/smarteetester/hosted.html?smarteetester:56
    (null,0,1)@http://localhost:8880:16
    (null,0,1)@http://localhost:8880:13
    anonymous(null,0,1)@http://localhost:8880/smarteetester/sc/modules/ISC_Grids.js:1007
    isc_GridRenderer__cellClick(null,0,1)@http://localhost:8880/smarteetester/sc/modules/ISC_Grids.js:811
    isc_GridRenderer__rowClick(0,1)@http://localhost:8880/smarteetester/sc/modules/ISC_Grids.js:808
    isc_GridRenderer_click([object Object],(void 0))@http://localhost:8880/smarteetester/sc/modules/ISC_Grids.js:805
    isc_Canvas_handleClick([object Object],(void 0))@http://localhost:8880/smarteetester/sc/modules/ISC_Core.js:3206
    isc_c_EventHandler_bubbleEvent([object Object],"click")@http://localhost:8880/smarteetester/sc/modules/ISC_Core.js:1646
    isc_c_EventHandler_handleClick([object Object])@http://localhost:8880/smarteetester/sc/modules/ISC_Core.js:1488
    isc_c_EventHandler__handleMouseUp([object MouseEvent],(void 0))@http://localhost:8880/smarteetester/sc/modules/ISC_Core.js:1475
    isc_c_EventHandler_handleMouseUp([object MouseEvent])@http://localhost:8880/smarteetester/sc/modules/ISC_Core.js:1466
    isc_c_EventHandler_dispatch(isc_c_EventHandler_handleMouseUp,[object MouseEvent])@http://localhost:8880/smarteetester/sc/modules/ISC_Core.js:1710
    anonymous([object MouseEvent])@http://localhost:8880/smarteetester/sc/modules/ISC_Core.js:60
    
    	at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
    	at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129)
    	at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    	at com.smartgwt.client.widgets.grid.events.GridRowColEvent.getRecord(GridRowColEvent.java)
    	at com.example.myproject.client.SmartEETester$23.onCellClick(SmartEETester.java:1089)
    SmartGWT 3
    Dev mode, FF 4.0.1
    SmartClient Version: SC_SNAPSHOT-2011-08-25/Pro Deployment

    #2
    Verified. The bug is actually that in this case there's no real underlying record -- the editValues were never saved due to the validation error.

    This will be fixed shortly - in the meantime you can workaround this by using the 'getEditedRecord(Integer rowNum);' API instead.

    [Edit]: Just to clarify - we'll fix the crash. The result of 'getRecord()' will be null in this case, and getEditedRecord() is the appropriate API to use.
    Last edited by Isomorphic; 10 Oct 2011, 10:57.

    Comment


      #3
      Ah, thanks for the edit. That would have been my 2nd question.

      Is this something we need to be aware of?

      For instance, if the row is OK, user changes a field so a validation error comes up. event.getRecord() will then contain the old values. So it probably only makes sense to always look at event.getEditedRecord() instead?

      Comment


        #4
        The "record" is the underlying data record, the "edited record" is the underlying data record + any unsaved edit values applied on top of it.

        So if the user has made edits which haven't been saved, either because the save failed due to validation errors, or because autoSaveEdits has been set to false and no explicit 'save' has been called, these will be present in the edited record (the result of "getEditedRecord()" rather than in the result of "getRecord").
        If the user is editing an entirely new record, of course there is no underlying data record.

        Comment

        Working...
        X