案例學習BlazeDS+Spring之四InSync02使用RemoteObject事件

來源:互聯網
上載者:User

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事件的處理, 服務端代碼沒有改動。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.