RemoteObject调用底层Java数据


1,main2.xml 代码

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#FFFFFF">

    //RemoteObject 用destination="product" 标识到remoting-config.xml

//<source>flex.samples.product.ProductService</source>在这个XML里有类的引用

    <mx:RemoteObject id="remote" destination="product"/>

//说明dataProvider不单有处理XML能力连JAVA集合也可以处理 getProducts是方法名返回List,.lastResult就像将数据序列化一样,其实也转成了XML数据

    <mx:DataGrid dataProvider="{remote.getProducts.lastResult}" width="100%" height="100%"/>

    //触发事件可以直接调用Java方法了哦。返回的数据用dataProvider装

    <mx:Button label="Get Data" click="remote.getProducts()"/>

   

</mx:Application>
 

2.在remoting-config.xml里配置如下:

<destination id="product">

        <properties>

            <source>flex.samples.product.ProductService</source>

        </properties>

</destination>

 

//其实DWR 一个JAVA的Ajax插件里面的原理也是用远程调用的。还有最前面的例子也是用事件远程调用一个HelloWorld 的只是用事件返回罢了:<mx:RemoteObject id="intojava" destination="helloFlex" result="resultHandle(event)">

而这里的例子是直接放入到<mx:DataGrid>里面去了。说明Flex对回调的数很是灵活

相关内容