Custom datasource with DMI and transformResponse

Hi,
I’m using the latest nightly build of SmartGWT EE 2.5 and I’d like to achieve the following: based on a set of records created on the server side (because of security concerns) I need to create on the client side another set of records of another type to be displayed into a grid. On the server the records are plain set of fields, on the client the records must be widgets.
I approached this problem trying to bind the grid to a datasource that creates the records on the server side using DMI and then transforms the records into widgets on the client side using transformResponse method. I didn’t succeed with this idea.
Could you please explain what is wrong with such an idea and what is the right solution for such a problem?

Thanks,Mihnea

That’s a really vague description, but if you want to create eg a record per component, one approach is ListGrid.showRecordComponents. Another is to just create a series of widgets in the DSCallback of DataSource.fetchData(), and put them in a VLayout.

Doing something like this in transformResponse is clearly wrong (and the docs for that method actually warn you of this!).

Hi, In the transformResponse I only create new Records based on existing ones and set them into the response data. See below.

	@Override
	protected void transformResponse(DSResponse response, DSRequest request,
			Object data) {
		if(response.getStatus()==0){
			final Record[] responseData = response.getData();
			final Record[] newData = new Record[responseData.length];
			
			for(int i=0; i<responseData.length; i++){
				Record item = responseData[i];			
				newData[i] = createNode(item.getAttributeAsString("nodeID"), item.getAttributeAsString("parentNodeID"));
			}
			response.setData(newData);
		}else{
			super.transformResponse(response, request, data);
		}
	}

Is it possible to have such a datasource with DMI and transformResponse method overridden?

The createNode method returns a custom TreeNode, not a widget.

Yes, with a server-based DataSource, when you call DataSource.get() you can pass in a RequestTransformer and ResponseTransformer.

While it’s OK to create something like a TreeNode in transformResponse, there’s no point in doing so. If you use a TreeGrid with this DataSource, TreeNodes are automatically created from the Record.

Even if you have some reason to create TreeNodes directly, the callback to DataSource.fetchData() is a more appropriate place to do this, since it won’t cause the DataSource to be specialized to use in Trees/TreeGrids only.

Ok, thanks for the hint.
Practically I need to enhance the records in the response transformer with attributes that have values as GWT classes.