使用lcds时,由于直接可以和java打交道,可以不用通过xml或者其他方式通信,用起来真的很方便,听说效率非常好,虽然不知道怎么来测试这效率,但还是很乐意去用它。数据从前台传到后台,后台处理后又将新数据传到前台,有人说web编程便是处理字符串,并不是没有道理的。
最先遇到的问题便是actionscript与java数据类型转换,比如在actionScript中定义一个int型的变量,传到后台时会自动对应为一个java的int型变量。但数据类型那么多,还真要好好列一列,当然不是自己去一个一个试,官方的文档里早就写好了。一个是actionScript 到java,一个是java到actionScipt,两张表:
从actionScript到java:
**************************************************************************
ActionScript type (AMF 3)
Deserialization to Java
Supported Java type binding
Array (dense)
|
java.util.List
|
java.util.Collection, Object
[ ] (native array)
If the type is an interface, it is mapped to the following interface implementations
- List becomes ArrayList
- SortedSet becomes TreeSet
- Set becomes HashSet
- Collection becomes ArrayList
A new instance of a custom Collection implementation is bound to that type.
|
Array (sparse)
|
java.util.Map
|
java.util.Map
|
Boolean
String of "true"
or "false"
|
java.lang.Boolean
|
Boolean, boolean, String
|
flash.utils.ByteArray
|
byte []
|
|
flash.utils.IExternalizable
|
java.io.Externalizable
|
|
Date
|
java.util.Date
(formatted for Coordinated Universal Time (UTC))
|
java.util.Date, java.util.Calendar, java.sql.Timestamp, java.sql.Time, java.sql.Date
|
int/uint
|
java.lang.Integer
|
java.lang.Double,
java.lang.Long, java.lang.Float, java.lang.Integer, java.lang.Short,
java.lang.Byte, java.math.BigDecimal, java.math.BigInteger, String,
primitive types of double, long, float, int, short, byte
|
null
|
null
|
primitives
|
Number
|
java.lang.Double
|
java.lang.Double,
java.lang.Long, java.lang.Float, java.lang.Integer, java.lang.Short,
java.lang.Byte, java.math.BigDecimal, java.math.BigInteger, String, 0
(zero) if null is sent, primitive types of double, long, float, int,
short, byte
|
Object (generic)
|
java.util.Map
|
If
a Map interface is specified, creates a new java.util.HashMap for
java.util.Map and a new java.util.TreeMap for java.util.SortedMap.
|
String
|
java.lang.String
|
java.lang.String,
java.lang.Boolean, java.lang.Number, java.math.BigInteger,
java.math.BigDecimal, char[], any primitive number type
|
typed Object
|
typed Object
when you use [RemoteClass] metadata that specifies remote classname. Bean type must have a public no args constructor.
|
typed Object
|
undefined
|
null
|
null for Object, default values for primitives
|
XML
|
org.w3c.dom.Document
|
org.w3c.dom.Document
|
XMLDocument
(legacy XML type)
|
org.w3c.dom.Document
|
org.w3c.dom.Document
You
can enable legacy XML support for the XMLDocument type on any channel
defined in the services-config.xml file. This setting is only important
for sending data from the server back to the client; it controls how
org.w3c.dom.Document instances are sent to ActionScript. For more
information, see
|
**************************************************************************
从java到actionScript:
**************************************************************************
Java type
|
ActionScript type (AMF 3)
|
java.lang.String
|
String
|
java.lang.Boolean, boolean
|
Boolean
|
java.lang.Integer
|
int
|
If i < 0xF0000000 || i > 0x0FFFFFFF, the value is promoted to Number.
|
java.lang.Short
|
int
|
If i < 0xF0000000 || i > 0x0FFFFFFF, the value is promoted to Number.
|
java.lang.Byte
|
int
|
If i < 0xF0000000 || i > 0x0FFFFFFF, the value is promoted to Number.
|
java.lang.Byte[]
|
flash.utils.ByteArray
|
java.lang.Double
|
Number
|
java.lang.Long
|
Number
|
java.lang.Float
|
Number
|
java.lang.Character
|
String
|
java.lang.Character[]
|
String
|
java.util.Calendar
|
Date
|
Datesare sent in the Coordinated Universal Time (UTC) time zone. Clients andservers must adjust time accordingly for time zones.
|
java.util.Date
|
Date
|
Dates are sent in the UTC time zone. Clients and servers must adjust time accordingly for time zones.
|
java.lang.Object (other than previously listed types)
|
Typed Object
|
Objects are serialized using Java Bean introspection rules. Fields that are static, transient, or nonpublic are excluded.
|
java.util.Collection
|
mx.collection.ArrayCollection
|
java.lang.Object[]
|
Array
|
java.util.Map
|
Object (untyped)
|
InFlex 1.5, java.util.Map was sent as an associative or ECMA Array. Thisis no longer a recommended practice. You can enable legacy Map supportto associative Arrays, but Adobe recommends against doing this. Formore information, see Providing legacy AMF serialization on a channel
|
java.util.Dictionary
|
Object (untyped)
|
org.w3c.dom.Document
|
XML object
|
Youcan
enable legacy XML support for the XMLDocument type on any
channeldefined in the services-config.xml file. For more information,
seeProviding legacy AMF serialization on a channel.
|
null
|
null
|
Other classes that extend java.lang.Object
|
Object (typed)
|
Objects are serialized using Java Bean introspection rules. Fields that are static, transient, or nonpublic are excluded.
|
**************************************************************************
这里面我用得最多的还是一些基本数据类型如:int ,Number,String等,其次便是ArrayCollection,上面的表里居然没有,ft,它对应的是java的list。当要传送大量数据时,当然不能一个数据一个数据地传,在as这边定义一个类A,同样在java方也定义一个类B,里面的成员变量一样。然后将类A与类B对应起来,在转换时类A便会转换为类B,当然反过来也可以。
要做到这样的一个类的对应很简单。
只要求在as方类定义前面加上一条代码[RemoteClass(alias="/*classname*/")]即可。如:
As方:
package{
[Bindable]
[RemoteClass(alias="com.zhan.PersonInfo")]
public class PersonInfo{
public var name:String;
public var age:int;
public var gender:Boolean;
}
}
Java方 (get set 就不写出来了
):
package com.zhan{
public class PersonInfo{
public String name;
public int age;
public boolean gender;
}
}
这样便将两个类对应了起来,其中有几个点要特别注意:
1.两个类对应成员命名要求一致,就是一模一样,这样转换时才知道将哪个成员转换为哪个成员
2.命名首字母要小写,
这个其实是一编程规范,有时候会忘了。
(这个规则上可是吃了亏的,怎么也不知道问题出在哪,查了半天,无意间将命名改为小写,居然就可以了,看来平时编程时还是要规范点)
3.java转换为as时,要求as类提拱默认构造函数(即不带参数)
,从java转换为as时,其实是构造一个as对象去接收,如果这个as类要求有带参数的构造函数,估计会把lcds搞晕,当然吃亏的还是自已
分享到:
相关推荐
使用lcds建立flex+java的web工程
lcds是用于来连接java数据库的哦!使用Flex 3 plugin+Eclipse+lcds 欢迎大家下载
Flex与JAVA,lcds,Flex与JAVA,lcds教程
Flex + LCDS +JAVA入门教程,描述了flex通过LCDS与java进行
精通flex3.0 精通 Flex3.0 LCDS ActionScript 事件
Flex+LCDS+Java入门教程,如何使用MyEclips进行配置
Flex_+_LCDS_+_Java_入门_教程 初学者很好的学习Flex的教程
Flex LCDS JAVA 入门学习教程
LCDS(LiveCycle Data Service)之前叫做FDS(Flex Data Service),他是基于java(也有ColdFusion版的)后端的数据服务工程,功能包括映射Java对象到Flex对象(包括调用Java类的方法)、RTMP(Real Time Message ...
关于flex java整合的案例,使用BlazeDS或LCDS整合flex和java技术,带整合步骤图片
Flex + LCDS + Java 详解
Flex + LCDS + Java Flex + LCDS + Java
Flex LCDS flex.war就是lcds.war Flex+LCDS使用的war包
Flex + LCDS + Java 入门教程Flex + LCDS + Java 入门教程Flex + LCDS + Java 入门教程
Flex LCDS Java 简单教程 源码
转:Flex+++LCDS+++Java+入门教程
精通Flex 3.0――14.1.2 ActionScript与Java数据类型的转换 精通Flex 3.0――14.1.3 LCDS的内容结构 精通Flex 3.0――14.2 一个最基本的LCDS应用 精通Flex 3.0――14.3 通过Remoting访问服务端的应用 精通Flex 3.0―...
flex利用LCDS整合J2EE进行web开发简单的测试工程
Flex + LCDS + Java 入门与配置