Flex 应用Remote与后台通信

 

1.创建模拟Services:(DataRomate.java类中getList()方法遍历数据)
Java代码 复制代码
  1. public class DataRomate    
  2. {   
  3.     public List getList()   
  4.     {   
  5.         List list = new ArrayList();   
  6.         for(int i=0;i<10; i++)   
  7.         {   
  8.             Map map = new HashMap();   
  9.             map.put("name""name"+i);   
  10.             map.put("description""description"+i);   
  11.             map.put("targeingexpression""targeingexpression"+i);   
  12.             map.put("userdby""userdby"+i);   
  13.             map.put("porfilechart""porfilechart"+i);   
  14.             list.add(map);   
  15.         }   
  16.         return list;  
public class DataRomate 
{
	public List getList()
	{
		List list = new ArrayList();
		for(int i=0;i<10; i++)
		{
			Map map = new HashMap();
			map.put("name", "name"+i);
			map.put("description", "description"+i);
			map.put("targeingexpression", "targeingexpression"+i);
			map.put("userdby", "userdby"+i);
			map.put("porfilechart", "porfilechart"+i);
			list.add(map);
		}
		return list;



2.配置:remoting-config.xml
Remoting-config.xml代码 复制代码
  1. <destination id="DataRo">   
  2.     <properties>   
  3.         <source>com.test.DataRomate</source>   
  4.     </properties>   
  5. </destination>  


3.*.mxml获取数据:
   A : getData(event:ResultEvent)方法实现数据绑定
Flex代码 复制代码
  1.   public function getData(event:ResultEvent):void   
  2.   {   
  3. dataGridId.dataProvider = event.result;   
  4.   }  


   B: 组件设置:
  
Flex代码 复制代码
  1. <mx:RemoteObject id="DataRo" destination="DataRo" result="getData(event)" />   


   C:设置DataGrid组件:
  
Flex代码 复制代码
  1.        
  2. <mx:DataGrid id="dataGridId" creationComplete="DataRo.getList()">   
  3.     <mx:columns>   
  4.     <mx:DataGridColumn dataField="name" headerText="Name"/>   
  5.     <mx:DataGridColumn dataField="description" headerText="Description"/>   
  6.            pression"/>   
  7.     <mx:DataGridColumn dataField="userdby" headerText="Used by"/>   
  8.     <mx:DataGridColumn dataField="porfilechart" headerText="Porfile Chart"/>   
  9.     </mx:column   
  10.      


   注意:creationComplete="DataRo.getList()" : getList()对应DataRomate.java类中getList()方法。
本文转自:http://lincoln-zhou.javaeye.com/blog/373356

posted on 2009-07-29 11:23  分布式编程  阅读(87)  评论(0编辑  收藏  举报

导航