Adobe® LiveCycle® Data Services ES 2.6 Developer Guide

Mapping client-side objects to Java objects

To represent a server-side Java object in a client application, you use the [RemoteClass(alias=" ")] metadata tag to create a strongly typed ActionScript object that maps directly to the Java object. You specify the fully qualified class name of the Java class as the value of alias. This is the same technique that you use to map to Java objects when using RemoteObject components.

You can use the [RemoteClass] metadata tag without an alias if you do not map to a Java object on the server but you do send back your object type from the server. The ActionScript object is serialized to a Map object when it is sent to the server, but the object returned from the server to the clients is your original ActionScript type. Both the client-side and server-side classes must contain an empty constructor. Also, the compiled SWF file must contain a reference to your ActionScript class. It the SWF file does not contain a reference to that class, a generic ASObject instance is created instead of the desired object type.

To create a managed association between client-side and server-side objects, you also use the [Managed] metadata tag or explicitly implement the mx.data.IManaged interface.

The CRM application that is included in the Adobe LiveCycle Data Services ES sample applications provides a good example of a managed association. The following example shows the source code for the client-side ActionScript Company class, which has a managed association with the server-side Java Company class:

package samples.crm
{
    [Managed]
    [RemoteClass(alias="samples.crm.Company")]
    public class Company
    {
        public var companyId:int;
        public var name:String = "";
        public var address:String = "";
        public var city:String = "";
        public var state:String = "";
        public var zip:String = "";
        public var industry:String = "";
        public function Company()
        {
        }
        
    }
}

The following example shows the source code for the corresponding server-side Java Company class. This example shows properties defined using the JavaBean style getX/setX syntax. You also can define public fields just as you do in ActionScript.

package samples.crm;

import java.util.Set;

public class Company
{
    private int companyId;
    private String name;
    private String address;
    private String city;
    private String zip;
    private String state;
    private String industry;

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    public String getCity()
    {
        return city;
    }

    public void setCity(String city)
    {
        this.city = city;
    }

    public int getCompanyId()
    {
        return companyId;
    }

    public void setCompanyId(int companyId)
    {
        this.companyId = companyId;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getState()
    {
        return state;
    }

    public void setState(String state)
    {
        this.state = state;
    }

    public String getZip()
    {
        return zip;
    }

    public void setZip(String zip)
    {
        this.zip = zip;
    }

    public String getIndustry()
    {
        return this.industry;
    }

    public void setIndustry(String industry)
    {
        this.industry = industry;
    }
    
    public String toString()
    {
        return "Company(companyId=" + companyId + ", name=" + name + ",
            address=" + address + 
            ", state" + state + ", zip=" + zip + " industry=" + industry + ")";
    }
}

Define a computed property in ActionScript

There can be times when you want your client-side managed classes to expose properties that are computed from the value of other properties. These types of properties tend to be read-only, but you want them to update properly when either of the source properties changes. It is fairly easy to add these constructs to your client-side managed classes. If you make these properties part of your data model, it is easier to show them as a column in a DataGrid component or use them to display a row in a list from an ItemRenderer object. Make sure you define these properties as transient with the [transient] metadata tag, since you do not want data management to track changes made to them or to serialize them to the server. You also must send PropertyChange events whenever either of the source properties has changed. The following code snippet implements a read-only displayName property by concatenating the firstName and lastName properties:

private var firstName:String;
private var lastName:String;
[Transient] 
public function get displayName():String {
    return _firstName + " " + _lastName;
}
public function get firstName():String {
    return _firstName;
}
public function set firstName(fn:String):void {
    var oldDN:String = displayName;
    firstName = fn;
    var newDN:String = displayName;
    dispatchEvent(PropertyChangeEvent.createUpdateEvent
        (this, "displayName", oldDN, newDN));
}
public function get lastName():String {
    return _lastName;
    }
public function set lastName(ln:String):void {
    var oldDN:String = displayName;
    lastName = ln;
    var newDN:String = displayName;
    dispatchEvent(PropertyChangeEvent.createUpdateEvent
        (this, "displayName", oldDN, newDN));
}


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/lcds/dms_client_6.html