com.smartgwt.client.docs
Interface ServerDataIntegration


public interface ServerDataIntegration

Server Data Integration means:

This approach is in contrast to 'Client-side Data Integration', which does not require the SmartGWT server, and in which client-side DataSources are configured to directly send and receive HTTP messages containing XML, JSON or other content.

Handling DataSource Requests

Client-side DataBoundComponent will send DSRequest to the ISC server as background communications transparent to the user. Integrating SmartGWT's DataSource layer with your data model is a matter of handling these DSRequests and sending back DSResponses, in order to fulfill the 4 basic operations of the 'DataSource Protocol'.

There are two approaches for routing inbound dsRequests to your business logic:

RPCManager dispatch
inbound requests are handled by a single dispatcher implemented as a Java servlet or .jsp. The RPCManager is used to retrieve requests and provide responses
com.smartgwt.client..DMI
XML declarations route requests to existing business logic methods. Inbound request data is adapted to method parameters, and method return values are delivered as responses

Which approach you use is largely a matter of preference. Direct Method Invocation (DMI) may allow simple integration without writing any SmartGWT-specific server code. RPCManager dispatch integration provides an earlier point of control, allowing logic that applies across different DataSource operations to be shared more easily.

Whether using RPCManager dispatch or DMI request routing, you must return data which, translated to JavaScript via the rules described in com.isomorphic.js.JSTranslater.toJS(), matches the 'response data required for the operationType'.

For example, for a "fetch" request, your return data should translate to an Array of JavaScript objects. Your backend may be capable of returning data in a number of ways - you should compare each format you can readily retrieve against the capabilities of the JSTranslater. Common options are to pass an XML document fragment or a Collection of Java Beans/POJOs directly to DSResponse.setData().

For "update" and "add" DataSource requests, the inbound data is intended to be permanently stored. If you are using a DataSource specified in XML format, you can run the validators you declared in the DataSource by calling the DSRequest.validate() method. Assuming the declared validation is passed, you can run custom validation logic, if any, and finally create or update objects in your object model. If you are using Beans/POJOs, the method DataSource.applyProperties(map, bean) is an easy way to apply the validated values to an Object tree or XML structure.

For more information on the DMI subsystem, see the com.smartgwt.client..DMI class and the DMI example in the SDK.

Note that, as you continue to integrate your prototype with your backend, you can use a mixture of DataSources that have been fully integrated with your backend and DataSources that are either running in "client-only" mode (see ClientOnlyDataSources) or that use ISC's built-in SQL connectivity (see SqlDataSource).

RPCManager dispatch

The basic flow of logic for handling DataSource requests using RPCManager dispatch is:

1. Get current list of requests from the client. rpcManager.getRequests()
2. Determine operation type (Fetch, Add, Update, Remove) for a single request. dsRequest.getOperationType()
3. Get inbound values (Add, Update) and/or criteria (Fetch, Update, Remove) for this request. dsRequest.getFieldValue()
dsRequest.getValues()
dsRequest.getCriteria()
4. Business logic, validation, calls to data and service tiers... anything you can code. execute custom logic
5. Set status and data for the response. dsResponse.setStatus()
dsResponse.setData()
6. Send response to the client. rpcManager.send()

For more information, see the RPCManager, and the RPCManager example.

See Also:
DataSource.getDataFormat(), DataSource.getDataProtocol(), com.smartgwt.client.data.DataSource#getRequestProperties, DataSource.getServerType(), DataSource.getTableName(), DataSource.getDbName(), com.smartgwt.client.data.DataSource#getServerObject, com.smartgwt.client.data.OperationBinding#getRequestProperties, DSDataFormat, DSServerType