Announcement

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

    saveAllEdits() does not fire callback

    Dear Isomorphic
    Since I've updated from SmartGWT 2.4 to 2.5 the attached (sample) code does not work anymore.
    In particular, the callback does not fire after saveAllEdits() if more than one row has been edited and the grid has fetched with criteria. Fetching without criteria (no restriction) works fine.
    Is this a bug or do I have to change my code?

    Code:
    public class Test extends VStack {
    	int edits = 1;
    	ListGrid grid = new ListGrid();
    	Label label1 = new Label("N/A");
    	Label label2 = new Label("N/A");
    	Label label3 = new Label("N/A");
    	
    	{
    		//create a local data source with test data and attach it to the grid
    		DataSource localDs = new DataSource();
    		localDs.setClientOnly(true);
    		localDs.setFields(getFields());
    		localDs.setTestData(getTestData());
    		
    		grid.setDataSource(localDs);
    		grid.setAutoSaveEdits(false);
    		
    		
    		//define the form items
    		final TextItem editItem = new TextItem("numberOfEdits", "<nobr>Number of edits</nobr>");
    		editItem.setValue(edits);
    		
    		ButtonItem edit = new ButtonItem("edit", "Edit");
    		edit.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
    			@Override
    			public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
    				edits = Integer.parseInt(editItem.getValueAsString());
    
    				for (int i = 0; i < edits; i++) {
    					Map<String, Object> values = new HashMap<String, Object>();
    					values.put("col2", "Z");
    					grid.setEditValues(i, values);
    				}
    				label1.setContents(DateUtil.formatAsShortDatetime(new Date()) + "-->hasChanges: " + grid.hasChanges());
    				label3.setContents(DateUtil.formatAsShortDatetime(new Date()) + "-->saveAllEdits callback not fired");
    				boolean saveSuccess = grid.saveAllEdits(new Function() {
    					@Override
    					public void execute() {
    						label3.setContents(DateUtil.formatAsShortDatetime(new Date()) + "-->saveAllEdits callback fired");
    					}
    				});
    				label2.setContents(DateUtil.formatAsShortDatetime(new Date()) + "-->saveAllEdits: " + saveSuccess);
    			}
    		});
    		edit.setStartRow(false);
    		
    		//create form and set the text and button
    		DynamicForm form = new DynamicForm();
    		form.setAutoWidth();
    		form.setNumCols(3);
    		form.setItems(editItem, edit);
    		
    		//set the layout
    		this.addMember(form);
    		this.addMember(grid);
    		this.addMember(label1);
    		this.addMember(label2);
    		this.addMember(label3);
    		
    		//that works!
    		//grid.fetchData();
    		
    		//that doesn't work!
    		grid.fetchData(new Criteria("col2", "S"));
    	}
    
    	private DataSourceField[] getFields() {
    		DataSourceField[] dsFields = new DataSourceField[3];
    		
    		DataSourceField dsField1 = new DataSourceField("pk", FieldType.INTEGER, "pKey");
    		dsField1.setPrimaryKey(true);
    		dsFields[0] = dsField1;
    		
    		DataSourceField dsField2 = new DataSourceField("col1", FieldType.TEXT, "COL1");
    		dsFields[1] = dsField2;
    		
    		DataSourceField dsField3 = new DataSourceField("col2", FieldType.TEXT, "COL2");
    		dsFields[2] = dsField3;
    		
    		return dsFields;
    	}
    	
    	private Record[] getTestData() {
    		Record[] records = new Record[6];
    		for (int i = 0; i < 5; i++) {
    			ListGridRecord record = new ListGridRecord();
    			record.setAttribute("pk" , i);
    			record.setAttribute("col1" , "A");
    			record.setAttribute("col2" , "S");
    			records[i] = record;
    		}
    		return records;
    	}
    	
    }

    #2
    Hi,

    I would like to add that I too am experiencing similar behavior (i.e. saveAllEdits() not firing the callback) in my application, and I can't seem to find a workaround. I have even tried the different flavors of saveAllEdits() with the same outcome. The only difference in my case is that this behavior seems to be intermittent, and I can't seem to put my finger on the exact reason that causes it to happen. The things that I noticed is that the more edited/added rows I have, the more likely it will happen. Also, hovering the mouse over the grid records as the save operations are taking place increases the odds of it happening. I am using a RestDataSource in my application, and running with SmartGWT 2.5 official build, and GWT 2.3 on Windows 7.
    I would really appreciate if someone from the SmartGWT team would provide some feedback on this. I am also willing to provide a standalone test case if needed.

    Thanks,
    Mike

    Comment


      #3
      Facing the same issue but I am using SmarClient not SmartGWT. It happens only if I select multiple rows. We upgraded from 7.2RC to 8.1 and are facing this issue.

      Comment


        #4
        The callback for saveAllEdits() fires only if all rows save successfully - no validation errors, including no validation errors on hidden fields (the latter case is reported in the Developer Console).

        Anyone seeing intermittent errors is probably experiencing intermittent failure to save server-side and should look at their server-side logs and logic.

        See also the editComplete and editFailed events if you need to react to individual row save failure or success.

        Comment


          #5
          I am not getting any validation errors or any server errors and below is what I am getting in SC console:

          16:26:13.953:XRP8:WARN:ListGrid:isc_ListGrid_7:Record:{DbId: 515,
          senderId: "01120"}, lost from local cache in paged result set. Pending edits for this record will be maintained.
          16:26:13.953:XRP8:WARN:ListGrid:isc_ListGrid_7:getCellRecord called with bad rowNum: undef
          16:26:13.953:XRP8:WARN:ListGrid:isc_ListGrid_7:Record:{DbId: 515,
          senderId: "01150"}, lost from local cache in paged result set. Pending edits for this record will be maintained.

          This is only happening in case when I select multiple rows and do some action. I getting control in callback for same records selecting individually.

          Comment


            #6
            This suggests that you are not returning data correctly from the server - your DSResponses either don't contain primary keys or contain wrong primary keys. See the FAQ on grids not updating.

            Comment


              #7
              Please see my initial code example. It reproduces the behavior and is a client only example with test data.

              Comment

              Working...
              X