【个人笔记】基于AMF-RPC实现Flex与JAVA的交互实例【下】

来源:互联网 发布:新浪微博刷活粉丝软件 编辑:程序博客网 时间:2024/06/16 02:29

上一例还有1种写法:

利用类型转换将JAVA传来的对象用AS对象进行接收转换。


注意:
             [Bindable][RemoteClass(alias="com.sxy.demo.StudentDao")] 数据绑定,与JAVA端的StudentDao类关联起来,此句一定要加!!!

package com.vo{[Bindable][RemoteClass(alias="com.sxy.demo.StudentDao")] public class Vo{public var id:int;public var name:String;public var sex:String;public var age:int;public var stclass:String;public var major:String;public var dep:String;public var type:String;}}

<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"    xmlns:s="library://ns.adobe.com/flex/spark"    xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:reflect="flex.lang.reflect.*"><fx:Declarations><mx:RemoteObject id="sxy" destination="Student" result="resultHandler(event)" endpoint="/FlexDao/messagebroker/amf"/></fx:Declarations><fx:Script>        <![CDATA[ import com.vof.Vo;import mx.collections.ArrayCollection;import mx.controls.Alert;import mx.rpc.events.FaultEvent;import mx.rpc.events.ResultEvent;  [Bindable]public var arr:ArrayCollection = new ArrayCollection();private function hello():void {      test.getInfo(t1.text);}private function resultHandler(event:ResultEvent):void {              arr = ArrayCollection(event.result)var vo_FlexData:ArrayCollection = new ArrayCollection();for (var i:int = 0; i < arr.length; i++)      {           var info:Vo = arr.getItemAt(i) as Vo;           vo_FlexData.addItem(info);                  }        datagrid.dataProvider = vo_FlexData;        } ]]>    </fx:Script>  <s:Panel width="1060" height="422"   title="学生信息查询" x="144.55" y="123"><s:VGroup x="22" y="14" width="102" height="73" >  <s:TextInput id="t1" width="98" height="35"/><s:Button label="查询" id="Button" click="hello()" width="55" height="26"/></s:VGroup>  <mx:DataGrid x="139" y="14" width="900" height="344"  id="datagrid"  showDataTips="true" verticalAlign="middle" ><mx:columns><mx:DataGridColumn headerText="学号" dataField="id"  resizable="true"/><mx:DataGridColumn headerText="姓名" dataField="name"  resizable="true"/><mx:DataGridColumn headerText="性别" dataField="sex"  resizable="true"/><mx:DataGridColumn headerText="年龄" dataField="age"  resizable="true"/><mx:DataGridColumn headerText="班级" dataField="stclass"  resizable="true"/><mx:DataGridColumn headerText="专业" dataField="major"  resizable="true"/><mx:DataGridColumn headerText="院系" dataField="dep"  resizable="true"/><mx:DataGridColumn headerText="类型" dataField="type"  resizable="true"/></mx:columns></mx:DataGrid></s:Panel></s:Application>

原创粉丝点击