I’m writing a project in GWT over GAE with SmartGWT.
I’ve got a DB with object, each having a “father” object and “sons”, and I’m using a TreeGrid to represent them. I already have a GWT-RPC service that gets the sons of a given node.
What I need now is to somehow extend the DataSource class s.t when a tree node is opened, I will be able to use my own service to go and fetch it’s sons – and then return them as something the TreeGrid can work with.
I know I’m suppose to override transformRequest and transformResponse, but I have no idea how. Any code sample / explanation will be greatly appreciated!
This is what I have so far – not sure it’s even remotely correct:
budgetTree.setDataSource(new DataSource() {
@Override
protected Object transformRequest(final DSRequest dsRequest) {
expensesService.getExpensesByYear(2008,
new AsyncCallback<ExpenseRecord[]>() {
@Override
public void onSuccess(ExpenseRecord[] result) {
System.out.println("Returned " + result.length + " expense record ");
dsRequest.setAttribute("dsResult", result);
}
@Override
public void onFailure(Throwable caught) {
System.out.println("Failed to run query");
}
});
return dsRequest;
}
@Override
protected void transformResponse(DSResponse response, DSRequest request,
Object data) {
Record[] recs = request.getAttributeAsRecordArray("dsResult");
response.setData(recs);
super.transformResponse(response, request, data);
}
});
Since you are performing the actual request yourself , you first need to look at
setDataProtocol(DSProtocol.CLIENTCUSTOM);Then in both
onSuccessandonFailureyou would need to callprocessResponse()which will calltransformResponse()}