6 July 2009
Note: Content on this page first appeared in the author's blog on June 24, 2009.
During the past several weeks, we have been adding new samples in the Flex Data Access category in Tour de Flex. All of the samples were created by either Christophe Coenraets or Holly Schinsky. Below is a brief overview of each.
Many of the samples described below utilize BlazeDS or LiveCycle DS. If you are unfamiliar with these products, I recommend Holly's Quick Start.
HTTPService – Basic Example
This one is fairly obvious – it demonstrates how to use the HTTPService to consume XML and other responses via HTTP or HTTPS. This is the most basic type of data access in Flex.
HTTPService – HTTPService Events
This sample builds on the previous sample and demonstrates how to handle result and fault events from HTTPService. Note that HTTPService calls are asynchronous so understanding these events is key.
HTTPService – E4X
This sample also uses HTTPService but specifies that the result format will be E4X
HTTPService – Using the Proxy Service (BlazeDS and LCDS)
All of the prior samples used the out-of-the-box HTTPService component to directly connect to the data source. Sometimes it is not practical to connect directly to the data source due to it being on a different domain (and lacking a crossdomain.xml entry) so a proxy service is needed. BlazeDS/LCDS can provide this proxy service with some simple configuration as described in this Tour de Flex sample.
WebService – Basic Example
Using the WebService tag, you can invoke SOAP-based web services. Objects returned by a web service are automatically de-serialized into ActionScript objects. Going the other way, ActionScript objects are passed as arguments to a web service operation and are serialized according to the WSDL description.
WebService – Using the Proxy Service (BlazeDS or LCDS)
Similar to our HTTPService Proxy section above, it is sometimes not practical or possible to connect directly to the service. Once again, the BlazeDS/LCDS proxy service provides a simple solution.
RemoteObject – Basic Java Remoting (BlazeDS or LCDS)
If you are connecting to a Java backend, it is possible to directly invoke methods of Java objects using RemoteObject. In addition to the obvious benefits of being able to call Java methods directly, you also get the benefits of AMF that is used to pass data back and forth. AMF is a compressed, binary format that is dramatically faster than verbose XML or other text formats. Lee Brimelow wrote a great blog post on AMF here. This Tour de Flex sample does a simple call to Flex.samples.product.ProductService, a simple Java class, a displays the data in a datagrid.
James Ward has created a great application that benchmarks AMF and compares it to several other data loading techniques.
RemoteObject – Basic Java Remoting 2 (BlazeDS or LCDS)
This sample is similar to the previous sample but also demonstrates handling result and fault events from the remote call (RemoteObject calls are asynchronous)
RemoteObject – RemoteObject Events (BlazeDS or LCDS)
Another good example of handling RemoteObject events.
RemoteObject – Strongly Typed Object (BlazeDS or LCDS)
This RemoteObject sample demonstrates how an ActionScript object is mapped to a remote Java object. The readme contains links to the backend Java source so you can see how each data attribute is mapped.
Basic Data Management (LCDS)
LiveCycle Data Services ES Data Management Service feature provides an efficient approach to synchronizing data across multiple views and between multiple clients. With LCDS, you don't have to keep track of changes made to the data, nor do you have to invoke remote services to notify the backend of the changes (create, update, delete) made on the client side. To demonstrate this, the sample prompts you to open a link in two different web browsers (the browsers can even be on different computers).
Each browser will display a data grid with a few rows of data. As you update the data in one browser, you'll see the changes immediately reflected in the other browser, keep the views in sync. This type of functionality typically requires rather complex code, but as you can see in the Tour de Flex sample, it's easy to implement using LiveCycle Data Services.
Conflict Management (LCDS)
This sample is similar to the previous sample in that you open a link in two browsers and each of the views stays in sync but this one also adds code to handle conflicts between the two users. Change data in a field on browser #1 AND in browser #2. When you save the data in one of the browsers, the other one will notify you of a conflict. This is another example of where LCDS can save a LOT of coding.
Managing Associations and Lazy Loading (LCDS)
This sample demonstrates how LCDS can load data on an as-needed basis (lazy). In this code, there are multiple many-to-one data relationships defined so that LCDS loads the associated data on demand.
Data Paging (LCDS)
This sample demonstrates automatic paging of large data sets. Rather than loading the entire query result set, the data is loaded on demand while keeping up with the latest changes to the data. Data paging speeds application response times and minimizes memory requirements client-side. The sample displays a simple datagrid that loads 100 rows at a time. As you scroll through the data, you will see brief delays as the next 100 rows are loaded. This is yet another example of LCDS saving the developer from having to write a lot of complex code.
Backend Persistence Options (LCDS)
At the end of the Data Management category is a subcategory demonstrating 3 different ways to manage data persistence used by the data management features. There is a sample that uses SQL, a sample that uses Hibernate and a sample that demonstrates how to build a more complex custom assembler.
Chat (BlazeDS or LCDS)
This sample demonstrates how to build a simple chat client that utilizes the publish/subscribe messaging provided by BlazeDS or LCDS.
Collaboration (BlazeDS or LCDS)
This sample uses publish / subscribe messaging to build a simple collaborative application. The sample prompts you to open a link in two or more browsers. When you click the button to switch the graph from company one to company two, the other clients will also switch.
Real-time dashboard (BlazeDS or LCDS)
This sample shows how to subscribe to a real-time data feed produced by the Tour de Flex server. The data is real and is produced by the Tour de Flex server. Each row in the data grid is produced when a sample is viewed in Tour de Flex. This is the foundation for the much more graphical dashboard.
More samples will be added to the Flex Data Access category very soon to demonstrate how to connect Flex applications to ColdFusion, .NET, PHP and other backends. Stay tuned!
UPDATE: .NET and PHP samples added by MidnightCoders.