While support for GWT is baked into Nuxeo, this native approach doesn't offer the flexibility I'm after to create composite applications where Nuxeo is just one source/sink of content. In previous applications, I have used a rest-client based approach using the RESTLET framework. However, I couldn't find any reasonable way to get the GWT datagrid control to play nicely using the restlet apporach. So, I switched gears, and returned to an HttpClient RPC approach for integrating GWT datagrids with Nuxeo.
What I do is bind the DataGrid to an AsyncDataProvider. The provider is set up in the corresponding presenter.
// Create a data provider.
dataProviderAsync = new LaborProfileAsyncDataProvider(SharedConstants.API_ACTION_LIST, eventBus);
dataProviderAsync.addDataDisplay(getView().getDataGrid());
addColumnSortAsyncHandling();
The provider's onRangeChanged method then contains the applicable RPC server call. Data is reflected into the datagrid control in the onSuccess method (updateRowData and updateRowCount). OnSuccess also fires an event that has a listener update on screen statistics.
// RPC Call
rpcService.getLaborProfileList(action, CurrentUser.getInstance().getUserName(),
CurrentSession.getInstance().getSessionId(),
CurrentUser.getInstance().getOwnerId(), searchFilter,
new AsyncCallback<ArrayList<LaborProfileRowFlat>>() {
@Override
public void onSuccess(ArrayList<LaborProfileRowFlat> result) {
if (result != null) {
filteredRowCount = result.size();
if ("".equals(searchFilter)) {
totalRowCount = filteredRowCount;
}
updateRowData(0, result);
updateRowCount(filteredRowCount, true);
eventBus.fireEvent(new UpdateLaborProfileStatsEvent());
}
}
});
The rpcService class prepares the command url (in url) and the Nuxeo transaction (in jsonString), and then handles the resulting JSON. The URL corresponds to a defined URL restlet pattern in Nuxeo (still using restlets on the Nuxeo side), from example the pattern <urlPattern>/laborprofile/{action}</urlPattern> is mapped to the Nuxeo restlet class that handles laborprofile transactions. The URL is the glue between the GWT caller and Nuxeo.
// MAKE THE CALL and PROCESS THE RESULT...
HttpEntity resEntity = HttpClientCall.execute(url, jsonString);
String resSource = "";
JsonNode rootNode = null;
JsonNode dataNode = null;
if (resEntity != null) {
...
The actual HttpClient call requires a bit more packaging (call to set-up security is removed) but is relatively trivial.
// MAKE THE CALL
DefaultHttpClient client = new DefaultHttpClient();
...
HttpPost postMethod = new HttpPost(url);
StringEntity reqEntity = null;
try {
reqEntity = new StringEntity(jsonString, "application/json", "UTF-8");
} catch (UnsupportedEncodingException e1) {
System.out.println("Error parsing jsonString");
}
if (reqEntity != null) {
reqEntity.setChunked(false);
postMethod.setEntity(reqEntity);
postMethod.setHeader("Connection", "close");
HttpResponse response = null;
try {
response = client.execute(postMethod);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// PROCESS THE RESULT...
HttpEntity resEntity = response.getEntity();
return resEntity;
}
Straighforward enough once you have worked out all the details.