The Ext GWT Loading API provides a powerful and flexible design for retrieving remote content. The Loading API consists of 3 parts: Loaders, DataProxies, and DataReaders.
Loaders are responsible for retrieving and formatting remote content. To accomplish this, loaders delegate work to the DataProxy and DataReader. The DataProxy is responsible for retrieving the remote content. The DataReader is responsible for parsing the raw data from the server into an expected format.
Ext GWT ships with several different types of DataProxies for retrieving remote content. The different data proxy types retrieve remote content in different ways.
HttpProxy retrieves remote content using a XMLHttpRequest (XHR) request. The request is made via the GWT RequestBuilder class. Any type of data may be returned such as XML or JSON data.
MemoryProxy is simple data proxy that returns data that is already in memory on the client. This is useful when you want to use the Loading API with local data. An example would be setting up a paging grid where paging is done via the Loading API.
RpcProxy retrieves its data using GWT RPC calls. GWT RPC provides the ability to pass Java objects back and forth from the server via a service interface.
ScriptTagProxy is used to circumvent the same origin policy enforced by the browsers. The same origin policy only allows scripts to make server calls to servers on the same domain that the executing script was loaded. ScriptTagProxy is useful as it allows you to make XHR calls to any server.
In the example we will query a YouTube JSON service to search for videos. The example will use 3 different data proxies to retrieve remote content. However, the same Loader and same DataReader code will be used for each of the 3 examples. Here is a screenshot of the example:
For this example, we will be calling a YouTube video service. Because of the same origin policy we cannot call the YouTube service directly. We will make a call to a Servlet on our server which will make the remote call and then return the requested data:
This article has demonstrated the different types of Ext GWT DataProxies and stepped through example code for HttpProxy, RpcProxy, and ScriptTagProxy.
The example and its code (written by Sven Brunken) were used during our session on loaders at our recent conference. Feel free to download the code used in this project and view the online demo of the completed project.