加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

案例学习BlazeDS+Spring之四InSync02使用RemoteObject事件

发布时间:2020-12-15 04:39:00 所属栏目:百科 来源:网络整理
导读:InSync02:使用RemoteObject事件 ? 一、运行DEMO: 1、运行程序:http://localhost:8400/spring-flex-testdrive/insync02/index.html; 二、理解代码: ? 1、insync02.mxml: s:RemoteObject id="ro" destination="contactService" fault="faultHandler(event

InSync02:使用RemoteObject事件

?一、运行DEMO:
1、运行程序:http://localhost:8400/spring-flex-testdrive/insync02/index.html;

二、理解代码:?
1、insync02.mxml:
<s:RemoteObject id="ro" destination="contactService" fault="faultHandler(event)" endpoint="http://localhost:8400/spring-flex-testdrive/messagebroker/amf">
??? <s:method name="findByName" result="resultHandler(event)"/>
</s:RemoteObject>

在本DEMO的主程序中,通过捕获RemoteObject的事件来处理远程调用。
失败的事件是放在s:RemoteObject里,而返回结果的事件是放在s:method方法里。

常用的RemoteObject事件有:

fault:服务调用失败并且操作自身不处理时,将分派 fault 事件。???
invoke:调用服务操作时,只要在通道尝试发送消息前没有引发错误,将分派 invoke 事件。?
result:服务调用成功返回并且操作自身不处理时,将分派 result 事件。


2、处理RemoteObject的事件:

private function resultHandler(event:ResultEvent):void
{
??? contacts = event.result as ArrayCollection
}
private function faultHandler(event:FaultEvent):void
{
??? Alert.show(event.fault.faultDetail);
}

3、本例中不再使用remoteObject操作方法的lastResult来绑定DataGrid的dataProvide,而是使用一个成员变量。
contacts是一个可绑定的集合类,
[Bindable] private var contacts:ArrayCollection;
在接收返回值的DataGrid,dataProvider="{contacts}"。这个用法也是与insync01的一个不同。 这个contacts成员变量会在接收到RemoteObject的返回结果事件后被赋值。

三、小结:

本DEMO与insync01相比,主要是增加了对RemotingObject事件的处理, 服务端代码没有改动。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读