Jul 08 2008
LiveCycle ES Data Services [Data Management] and Java Enums
Disease :
You want to use LiveCycle ES Data Services on top of a Java back-end that is using Java enums.
Prescription :
LiveCycle ES Data Services 2.6 supports Java enums. When serializing from Java to ActionScript, Data Services will transform the Java enum value into an ActionScript String. When serializing from ActionScript to Java, Data Services will assign the correct enum value to the corresponding Java attribute.
Let’s see how it looks like. To get started we create a LiveCycle ES Data Services project (What is the preferred LiveCycle Data Services development environment). In the next part we will run through all the steps needed to develop a LiveCycle ES Data Services Data Manangement application.
The Java side
The Java enum looks like this
|
package myenum.test; public enum MyEnum { |
The DTO looks like this:
|
package myenum.test; public class MyDTO { public int id; |
LiveCycle ES Data Services Data Management automatically takes care of all DTO’s that are modified and retrieved by the Flex application (created, deleted and updated objects). When a client side "commit" operation is invoked the modifications are sent to the server. Those changes are mapped to your back-end via an assembler class. Typically this class implements four methods (fill, createItem, updateItem and deleteItem). In this example the assembler class looks like this:
|
package myenum.test; import java.util.ArrayList; import flex.data.assemblers.AbstractAssembler; public class MyAssembler extends AbstractAssembler { @Override @Override @Override MyDTO myDTO = (MyDTO) previousVersion; @Override MyDTO myDTO = (MyDTO) newVersion; |
In the real world these methods will be calling your specific services to retrieve and process the information.
Before we go to the Flex client we need to configure a Data Management endpoint by configuring the data-management-config.xml file in your LiveCycle ES Data Services project (located in WEB-INF/flex)
|
<destination id="myds"> <adapter ref="java-dao" /> <properties> <auto-sync-enabled>true</auto-sync-enabled> <use-transactions>false</use-transactions> <source>myenum.test.MyAssembler</source> <metadata> <network> <server/> </properties> </destination> |
The Flex side
The ActionScript DTO (it maps directly to the Java class):
|
package vo } |
The Flex application:
|
<?xml version="1.0" encoding="utf-8"?> <mx:Script> private function createMyDTO():void { ]]>
<mx:DataService id="myDS" destination="myds" autoCommit="false"/> <mx:Panel x="116" y="49" width="488" height="204" layout="absolute"> |
On the Java side "car" is a enum while in ActionScript it is a String. Assigning "BMW" to a newly created myVO results serverside in a new myVO with the car enum equal to BMW.
Notice that there are no explicit calls made to the server for creating, deleting or updating the DTO’s. The only interaction with the server happens through the fill and the save operation. LiveCycle ES Data Services Data Management takes care of the hard work.
You can download the sources for this sample as a LiveCycle ES Data Services project archive from Adobe Share, next import this into your Eclipse + Flex plugin environment.
Tip to stay healthy:
Check out Christophe Coenraets‘ website to find more examples about LiveCycle ES Data Services. You can download LiveCycle ES Data Services 2.6 (beta) from Adobe Labs.
[...] assembler you execute (see PersonAssember in the code sample). For more info on assemblers, go to Dr Flex & Dr. LiveCycle or consult the LiveCycle Data Services Developer [...]
does this work without using a DataService object? I am using a Consumer to listen to a JMS topic…but it doesn’t seem to work.