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

上一例还有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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值