Showcase

0 comments0 views
1 Star2 Stars

flex Class Mappings

Category: Learn Flex, flex tutorials    |    5 views    |    Add a Comment

To map a server-side Java object to a client-side ActionScript object, you use the [RemoteClass(alias=”")] metadata tag. You must specify the package and class name of the Java object in the alias value. This is the same technique used when you map client and Java objects using RemoteObject components.

If you do not want to map the ActionScript object to the Java object, but do want it mapped from the server to client, just specify the [RemoteClass] metadata tag without the alias value.

The following example shows an ActionScript object that is mapped to a Java object called com.mycompany.vo.User:

 package com.learningpc.livecourse.vo {       [Bindable]
      [RemoteClass(alias=”com.mycompany.vo.UserVO”)]
      public class UserVO
      {
           public var id:Number;           public var sessionkey:Str
ing;           public var username:String;
           public var password:String;           public var firstname:String;
           public var middlename:String;
           public var lastname:String;
           public var photo:String;
           public var emailaddress:String;
           public var logincount:Number;
           public var lastlogindate:Date;
           public var lastlogoutdate:Date;           public var homepage:String;
           public var usertype:String;
           public var lastIp:String;
           public var active:Number;      } }

The following shows the corresponding Java object contact:

 package com.learningpc.livecourse.vo;  import java.io.Serializable;  public class User implements Serializable {      private static final long serialVersionUID = 4832904328320999999L;       private int id;
      private String usern
ame;      private String password;
      private String firstname;
      private String lastname;
      private String emailaddress;       public static long getSerialVersionUID()      {
           return serialVersionUID;      }       public String getEmailaddress()      {
           return emailaddress;      }       public void setEmailaddress(String emailaddress)      {
           this.emailaddress = emailaddress;      }       public String getFirstname()      {
           return firstname;
      }       public void setFirstname(String firstname)      {
           this.firstname = firstname;      }       public int getId()      {
           return id;      }       public void setId(int id)      {
           this.id = id;      }       public String getLastname()      {
           return lastname;      }       public void setLastname(String lastname)      {
           this.lastname = lastname;      }       public String getPassword()      {           return password;      }       public void setPassword(String password)      {
           this.password = password;      }       public String getUsername()      {
           return username;      }       public void setUsername(String username)      {
           this.username = username;      } 
      public String toString()      {
           StringBuffer sb = new StringBuffer();           sb.append(username);
           sb.append(” “);
           sb.append(password);           sb.append(” “);
           sb.append(firstname);           sb.append(” “);
           sb.append(lastname);
           return sb.toString();      } }

Share/Save/Bookmark

 

Distributed Data Application

Category: Learn Flex, flex tutorials    |    1 views    |    Add a Comment

As you know by now, Data Management Service allows you to distribute and synchronize data among multiple clients. This section describes how to create client-side Flex applications that can show and distribute data.

Distributed Data Application

A Flex application uses a Data Service component to receive data and send data to the server-side Data Management Service. The data travels over a protocol-specific message channel to and from the Data Manage ment Service. You can manage an ArrayCollection object on multiple clients by using a Data Service component. Any changes made to the data synchronize with the rest of the clients.

The following example creates and fills an ArrayCollection object in ActionScript. The fill() method populates the Array Collection object with data from the Data Management Service destination.

 <?xml version=”1.0″ encoding=”utf-8″?>
 <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml
      creationComplete=”initUI()”>       <mx:Script>
           <![CDATA[                 import mx.collections.ArrayCollection;
                import mx.data.DataService;                 public var ds:DataService;                 [Bindable]
                public var ac:ArrayCollection;                 public function initUI():void                {
                     ac = new ArrayCollection();
                     ds = new DataService(”myDestination”);
                     ds.fill(ac);                }            ]]>      </mx:Script>  </mx:Application>

The following example shows a manual update of an item in an Array Collection object. The commit() method of the Data Service object sends the changes to the Data Management Service destination.

 var users:ArrayCollection = new ArrayCollection();
 var userDS:DataService = new DataService(”myUserDestination”);
 userDS.autoCommit = false;  var user:User = users.getItemAt(10);
 user.firstname = “Simon”;
 userDS.fill(users);
 userDS.commit();

Call the DataService.disconnect() method to disconnect connected clients. The Data Service component keeps a copy of its managed data and will resubscribe to pick the changes when you reconnect.

Share/Save/Bookmark

 

flex Data Management Services

Category: Learn Flex, flex tutorials    |    1 views    |    Add a Comment

The Data Management Service feature uses client-side and server-side functionality to distribute data among multiple clients and server tiers. The client-side contains the DataService component in ActionScript that works in conjunction with the server-side Data Management Service to provide distributed data. The Data Service component manages data on the client, while the server-side Data Management Service manages the distribution of data among multiple clients and server-side data resources.

Data Management Service vs. RPC Features

The Data Management Service employs a different approach to data than the RPC approach. Data Management Service supports automatic and manual synchronization of a common set of data on multiple clients and server-side data. It also supports offline client-side data persistence for occasionally connected clients. RPC components invoke operations on a remote service that return static results that you bind into an object. Data Management Service is different. The set of data is replicated to multiple clients from the Data Manage ment Service and data is changed. The changes are automatically set to the Data Management Service, which updates the data resource and client applications.

Data Management Service Data Flow

A Data Management Service application uses the Flex messaging framework, discussed earlier in this chapter. Instead of having a client application as the producer and another client application as a consumer, Data Management Services client applications act as both producers and consumers.

Figure 11-4 shows the flow of data between the server-side data resource and an Array Collection object.

Image from book
Figure 11-4: Flow of data between the server-side data resource and an Array Collection object

A Data Management Service uses an adapter to update a data store. If data in one or more clients changes, the Data Management Service automatically synchronizes all client and server versions of the data. Any changes to database or directories do not automatically propagate back into the Data Management Service and client applications.

The Data Management Service also provides functionality for server-side and client-side conflict resolution (APIs for handling data synchronization conflicts).

Data Synchronization Conflicts

When one or more clients change the same piece of data at the same time, data synchronization conflicts can occur. There is an API for detecting and handling data synchronization conflicts, and ensuring the integrity of distributed data by limiting any further changes until conflicts are resolved. The Data Management Service can detect when a data update from a client is out-of-date and inform the client of the conflict.

Share/Save/Bookmark