您的位置:首页 > 编程语言 > Java开发

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

2012-02-20 20:08 746 查看
上一例还有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>
&
4000
lt;![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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息