SmartGWT v9.0p_2014-03-06/PowerEdition Deployment (built 2014-03-06)
I have a ListGrid backed by a client only datasource. The datasource is loaded by calling setCacheData() since it will contain several thousand records that are built from three different datasources on the server.
When I update a record by calling ds.updateData() with only a subset of the record's fields, any subsequent calls to ds.fetchData() for that record will only return what was sent in the update. However, if I invoke invalidateCache() on the ListGrid, it will load the ListGrid with the entire record.
Should I update the ListGrid directly instead of trying to do this thru the data source? Or is there something I'm missing with regard to interacting with the client side datasource in this manner? I've created the test case below that demonstrates the problem.
The first time you click the update button, the first fetch and the update will show the full record in the respective text areas. The second fetch (which occurs after the update) only shows the fields passed in the update record. Repeatedly clicking Update then shows that all calls to fetch only return the updated fields.
The RecordUtil.recordToString() method iterates over all the attributes in the given record and separates them with EOL.
I have a ListGrid backed by a client only datasource. The datasource is loaded by calling setCacheData() since it will contain several thousand records that are built from three different datasources on the server.
When I update a record by calling ds.updateData() with only a subset of the record's fields, any subsequent calls to ds.fetchData() for that record will only return what was sent in the update. However, if I invoke invalidateCache() on the ListGrid, it will load the ListGrid with the entire record.
Should I update the ListGrid directly instead of trying to do this thru the data source? Or is there something I'm missing with regard to interacting with the client side datasource in this manner? I've created the test case below that demonstrates the problem.
The first time you click the update button, the first fetch and the update will show the full record in the respective text areas. The second fetch (which occurs after the update) only shows the fields passed in the update record. Repeatedly clicking Update then shows that all calls to fetch only return the updated fields.
The RecordUtil.recordToString() method iterates over all the attributes in the given record and separates them with EOL.
Code:
public Layout createTestLayout() { HLayout layout = new HLayout(); final DataSource ds = new DataSource(); ds.setID("clientDS"); ds.setClientOnly(true); List<DataSourceField> dsFields = new ArrayList<DataSourceField>(); DataSourceField f = new DataSourceField("id", FieldType.INTEGER); f.setPrimaryKey(true); dsFields.add(f); dsFields.add(new DataSourceField("a", FieldType.TEXT)); dsFields.add(new DataSourceField("b", FieldType.TEXT)); dsFields.add(new DataSourceField("c", FieldType.TEXT)); ds.setFields(dsFields.toArray(new DataSourceField[] {})); List<ListGridField> lgFields = new ArrayList<ListGridField>(); lgFields.add(new ListGridField("a", 20)); lgFields.add(new ListGridField("b", 20)); lgFields.add(new ListGridField("c", 20)); final ListGrid grid = new ListGrid(); grid.setDataSource(ds); grid.setAutoFetchData(true); grid.setWidth(400); grid.setHeight(400); List<ListGridRecord> data = new ArrayList<ListGridRecord>(); for (int i = 1; i < 15; i++) { ListGridRecord r = new ListGridRecord(); r.setAttribute("id", i); r.setAttribute("a", "aaaaaa" + i); r.setAttribute("b", "bbbbbbb" + i); r.setAttribute("c", "cccccc" + i); data.add(r); } grid.getDataSource().invalidateCache(); grid.invalidateCache(); ds.setCacheData(data.toArray(new ListGridRecord[] {})); DynamicForm form = new DynamicForm(); List<FormItem> items = new ArrayList<FormItem>(); final TextAreaItem taRec = new TextAreaItem("FetchedRecord1"); taRec.setWidth(400); taRec.setHeight(100); items.add(taRec); final TextAreaItem taResp = new TextAreaItem("UpdateResponse"); taResp.setWidth(400); taResp.setHeight(100); items.add(taResp); final TextAreaItem taRec2 = new TextAreaItem("FetchedRecord2"); taRec2.setWidth(400); taRec2.setHeight(100); items.add(taRec2); form.setFields(items.toArray(new FormItem[] {})); final IButton btn = new IButton("Update"); btn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { ds.fetchData(new Criteria("id", "1"), new DSCallback() { @Override public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) { Record r = dsResponse.getData()[0]; taRec.setValue(RecordUtil.recordToString(r)); Record updatedRecord = new Record(); updatedRecord.setAttribute("id", 1); updatedRecord.setAttribute("a", "zzzzz"); ds.updateData(updatedRecord, new DSCallback() { @Override public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) { Record r = dsResponse.getData()[0]; taResp.setValue(RecordUtil.recordToString(r)); ds.fetchData(new Criteria("id", "1"), new DSCallback() { @Override public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) { Record r = dsResponse.getData()[0]; taRec2.setValue(RecordUtil.recordToString(r)); grid.invalidateCache(); } }); } }); } }); } }); layout.addMember(grid); layout.addMember(form); layout.addMember(btn); return layout; }
Comment