【flex cookbook】如何使用远程对象

来源:互联网 发布:淘宝秒刷销量 编辑:程序博客网 时间:2024/06/09 02:32
如何使用远程对象
问题摘要
你需要改善你的数据传输性能,你需要能够直接调用服务器上java对象的方法
解决摘要
使用BlazeDS远程对象,应能够直接调用部署在远程服务器上的java对象的方法,并且获得返回值,绘制的类型可以是原始类型,一个对象,或者是一张图,一列对象……
解释
使用远程对象是很简单的
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
          
<mx:RemoteObject id="srv" destination="product"/>
          
<mx:DataGrid dataProvider="{srv.getProducts.lastResult}" width="100%" height="100%"/> 
          
<mx:Button label="Get Data" click="srv.getProducts()"/>   
</mx:Application>
远程对象的目标属性的值,通过
remoting-config.xml配置文件与相关的Java类完全映射,
服务器端的Java对象的方法返回的值被序列化为AS对象,这个例子中我们并没有提到与AS文件对应的服务端的方法,在例子5中我们将给出一个完全的版本
源文档
<http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=7766>
 
Problem Summary 问题摘要
You need to improve your data transfer performance. You also want to be able to directly invoke methods of Java objects deployed in your application server.
Solution Summary
Using the BlazeDS RemoteObject, you can directly invoke methods of Java objects deployed in your application server, and consume the return value. The return value can be a value of a primitive data type, an object, a collection of objects, an object graph, etc.
Explanation
Using RemoteObject is easy:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
          
<mx:RemoteObject id="srv" destination="product"/>
          
<mx:DataGrid dataProvider="{srv.getProducts.lastResult}" width="100%" height="100%"/> 
          
<mx:Button label="Get Data" click="srv.getProducts()"/>   
</mx:Application>
The value of the destination property of RemoteObject is a logical name that is mapped to a fully qualified java class in remoting-config.xml.
Java objects returned by server-side methods are deserialized into either dynamic or typed ActionScript objects. In this example, we don't have an explicit ActionScript version of the Product Java class. Product objects are therefore deserialized into dynamic objects. In sample 5, we work with an explicit Product class in ActionScript.
 
原创粉丝点击