Flex provides two ways to pass parameters to a service call: explicit parameter passing and parameter binding. With explicit parameter passing, pass properties in the method that calls the service. With parameter binding, use data binding to populate the parameters from user interface controls or data models.
The following example shows MXML code for declaring a RemoteObject component and calling a service using explicit parameter passing in the click event listener of a Button control. A ComboBox control provides data to the service.
<?xml version="1.0"?>
<!-- ds\rpc\RPCParamPassing.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
[Bindable]
public var empList:Object;
]]>
</mx:Script>
<mx:RemoteObject
id="employeeRO"
destination="SalaryManager"
result="empList=event.result;"
fault="Alert.show(event.fault.faultString, 'Error');"/>
<mx:ComboBox id="dept" width="150">
<mx:dataProvider>
<mx:ArrayCollection>
<mx:source>
<mx:Object label="Engineering" data="ENG"/>
<mx:Object label="Product Management" data="PM"/>
<mx:Object label="Marketing" data="MKT"/>
</mx:source>
</mx:ArrayCollection>
</mx:dataProvider>
</mx:ComboBox>
<mx:Button label="Get Employee List"
click="employeeRO.getList(dept.selectedItem.data);"/>
</mx:Application>
Parameter binding lets you copy data from user interface controls or models to request parameters. When you use parameter binding with RemoteObject components, you always declare operations in a RemoteObject component's <mx:method> tag. You then declare <mx:arguments> tags under an <mx:method> tag.
The order of the <mx:arguments> tags must match the order of the method parameters of the service. You can name argument tags to match the actual names of the corresponding method parameters as closely as possible, but it is not necessary.
The following example uses parameter binding in a RemoteObject component's <mx:method> tag to bind the data of a selected ComboBox item to the employeeRO.getList operation when the user clicks a Button control. When you use parameter binding, you call a service by using the send() method with no parameters.
<?xml version="1.0"?>
<!-- ds\rpc\ROParamBind2.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.utils.ArrayUtil;
]]>
</mx:Script>
<mx:ArrayCollection id="employeeAC"
source="{ArrayUtil.toArray(employeeRO.getList.lastResult)}"/>
<mx:RemoteObject
id="employeeRO"
destination="roDest"
showBusyCursor="true"
fault="Alert.show(event.fault.faultString, 'Error');">
<mx:method name="getList">
<mx:arguments>
<deptId>{dept.selectedItem.data}</deptId>
</mx:arguments>
</mx:method>
</mx:RemoteObject>
<mx:HBox>
<mx:Label text="Select a department:"/>
<mx:ComboBox id="dept" width="150">
<mx:dataProvider>
<mx:ArrayCollection>
<mx:source>
<mx:Object label="Engineering" data="ENG"/>
<mx:Object label="Product Management" data="PM"/>
<mx:Object label="Marketing" data="MKT"/>
</mx:source>
</mx:ArrayCollection>
</mx:dataProvider>
</mx:ComboBox>
<mx:Button label="Get Employee List" click="employeeRO.getList.send();"/>
</mx:HBox>
<mx:DataGrid dataProvider="{employeeAC}" width="100%">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name"/>
<mx:DataGridColumn dataField="phone" headerText="Phone"/>
<mx:DataGridColumn dataField="email" headerText="Email"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
If you are unsure whether the result of a service call contains an Array or an individual object, use the toArray() method of the mx.utils.ArrayUtil class to convert it to an Array, as this example shows. If you pass the toArray() method an individual object, it returns an Array with that object as the only Array element. If you pass an Array to the method, it returns the same Array. For information about working with ArrayCollection objects, see the Flex Help Resource Center.
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_6.html