懒得废话直入主题!
先把效果贴上来,通过点击 “获取列表” 按钮取得数据绑定。

定义javabean User.java
// Fields
private Integer userId;
private String userName;
private String password;
private String email;
// Property accessors get...set...
提供Flex调用 HelloWorld.java
//调用的方法
public List getList() {
List list = userService.getList();
return list;
}
remoteing-config.xml注册HelloWorld类。这里我整合了spring,用的是网络中提供的SpringFactory.
<destination id="User">
<properties>
<factory>spring</factory>
<source>helloWorld</source>
</properties>
</destination>
服务端基本就这样啦,接下来我们看客户端的Flex
<mx:RemoteObject id="user" destination="User"> <mx:method name="getList" result="listHandleResult(event)"/> </mx:RemoteObject>
这是定义一个远程对象,也就是我们在remoteing-config.xml中配置的Helloworld。
mx:method配置了当用户调用getList方法时指定回调函数为listHandleResult,接下来看回调函数。
public function listHandleResult(event:ResultEvent):void
{
var arr= event.result;
dg.dataProvider=arr;
}
很简单,通过event.result获得返回用户列表并转换成as对象,然后将它绑定到datagrid中。下面就是datagrid。
<mx:DataGrid width="300" height="300" x="27" y="28" id="dg" fontSize="12">
<mx:columns>
<mx:Array>
<mx:DataGridColumn dataField="userName" headerText="Name"/>
<mx:DataGridColumn dataField="email" headerText="Email"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>
最后看看通过用户点击 获得list 激发操作
<mx:Button x="352" y="29" label="获得list" click="remotingList(event)" fontSize="12"/>
public function remotingList(event:Event):void{
user.getList();
}
这个不描叙啦。
诶~~~老板让我两个星期搞个Flex+java的触摸屏导航系统,有点小小压力,不过听happy!!
本文介绍了一种使用Flex客户端与Java服务器端进行远程数据交互的方法。通过定义JavaBean实现数据封装,利用RemoteObject组件及回调函数实现数据绑定至DataGrid。
199

被折叠的 条评论
为什么被折叠?



