Define the RemoteObject components in your client-side Flex application in MXML or ActionScript. The following example defines a RemoteObject component using both techniques:
<?xml version="1.0"?>
<!-- ds\rpc\ROInAS.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="useRemoteObject();">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
public var asService:RemoteObject;
public function useRemoteObject():void {
asService = new RemoteObject();
asService.destination = "ro-catalog";
asService.getList.addEventListener("result", getListResultHandler);
asService.addEventListener("fault", faultHandler);
asService.getList();
}
public function getListResultHandler(event:ResultEvent):void {
// Handle the result by accessing the event.result property.
}
public function faultHandler (event:FaultEvent):void {
// Deal with event.fault.faultString, etc.
Alert.show(event.fault.faultString, 'Error');
}
]]>
</mx:Script>
<!-- Define the RemoteObject component in MXML. -->
<mx:RemoteObject
id="mxmlService"
destination="ro-catalog"
result="getListResultHandler(event);"
fault="faultHandler(event);"/>
<mx:Button label="MXML" click="mxmlService.getList();"/>
<mx:Button label="AS" click="asService.getList();"/>
</mx:Application>
The destination specifies the Java class associated with the remote service. A Java class can expose multiple methods, corresponding to multiple operations. In this example, you directly call the getList() operation in response to a click event of a Button control.
Because a single RemoteObject component can invoke multiple operations, the component requires a way to represent information specific to each operation. Therefore, for every operation, the component creates an mx.rpc.remoting.mxml.Operation object.
The name of the Operation object corresponds to the name of the operation. From the example shown in Calling a service, you access the Operation object that corresponds to the getList() operation by accessing the Operation object named getList, as the following code shows:
// The Operation object has the same name as the operation, without the trailing parentheses. var myOP:Operation = mxmlService.getList;
The Operation object contains properties that you use to set characteristics of the operation, such as the arguments passed to the operation, and to hold any data returned by the operation. You access the returned data by using the Operation.lastResult property.
Invoke the operation by referencing it relative to the RemoteObject component, as the following example shows:
mxmlService.getList();
Alternatively, invoke an operation by calling the Operation.send() method, as the following example shows:
mxmlService.getList.send();
When a service defines multiple operations, you define multiple methods for the RemoteObject component and specify the attributes for each method, as the following example shows:
<mx:RemoteObject
id="mxmlService"
destination="ro-catalog"
result="roResult(event);">
<mx:method name="getList" fault="getLFault(event);"/>
<mx:method name="updateList" fault="updateLFault(event);"/>
<mx:method name="deleteListItem" fault="deleteLIFault(event);"/>
</mx:RemoteObject>
The name property of an <mx:method> tag must match one of the operation names. The RemoteObject component creates a separate Operation object for each operation.
Each operation can rely on the event handlers and characteristics defined by the RemoteObject component. However, the advantage of defining the methods separately is that each operation can specify its own event handlers, its own input parameters, and other characteristics. In this example, the RemoteObject component defines the result handler for all three operations, and each operation defines its own fault handler. For an example that defines input parameters, see Using parameter binding to pass parameters to the RemoteObject component.
The concurrency property of the <mx:method> tag indicates how to handle multiple calls to the same method. By default, making a new request to an operation or method that is already executing does not impact the existing request.
The following values of the concurrency property are permitted:
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/lcds/rpc_remoteobject_4.html