flex中对Java返回list类型的处理

flex中对Java返回list类型的处理

后台的Java程序返回一个list类型而前台的的flex对其进行读取,这个该怎么办呢?
返回list的Java代码

 1  package  com.duduli.li;
 2 
 3  import  java.util.ArrayList;
 4  import  java.util.Date;
 5  import  java.util.List;
 6 
 7  public   class  Testlist {
 8      @SuppressWarnings( " unchecked " )
 9       public  List returnList(){
10 
11          Perl p  =   new  Perl();
12          p.setId( 1 );
13          p.setName( " tom " );
14          p.setDate( new  Date());
15 
16          Perl p2  =   new  Perl();
17          p2.setId( 2 );
18          p2.setName( " john " );
19          p2.setDate( new  Date());
20 
21          Perl p3  =   new  Perl();
22          p3.setId( 3 );
23          p3.setName( " cate " );
24          p3.setDate( new  Date());
25      
26          List < Perl >  list  =   new  ArrayList();
27          list.add(p);
28          list.add(p2);
29          list.add(p3);
30          
31           return  list;
32      }
在remoting-config.xml注册好。
1       < destination  id ="returnlist" >
2           < properties >
3               < source > com.duduli.li.Testlist </ source >
4           </ properties >
5       </ destination >
前台的flex用一个DataGrid来显示
使用remoteobject,调用注册的destination。
< mx:RemoteObject  id ="rl"  destination ="returnlist"  result ="resultHandler(event)" />
结果由result="resultHandler(event)"的方法处理
下面就是关键的代码了
 1      [Bindable]
 2          public var ac:ArrayCollection = null;
 3          
 4           public function bind():void{
 5              rl.returnList();
 6          }  
 7          
 8         private function resultHandler(event:ResultEvent):void {
 9              ac = ArrayCollection(event.result);
10          } 
下面则是显示的
1           < mx:DataGrid  x ="205"  y ="303"  dataProvider ="{ac}"  creationComplete ="bind()" >
2                   < mx:columns >
3                           < mx:DataGridColumn  headerText ="id"  dataField ="id" />
4                           < mx:DataGridColumn  headerText ="name"  dataField ="name" />
5                           < mx:DataGridColumn  headerText ="date"  dataField ="date" />
6                   </ mx:columns >
7           </ mx:DataGrid >
其中creationComplete="bind()"是在程序运行的时候进行调用的(我是这样认为的)。

你可能感兴趣的:(flex中对Java返回list类型的处理)