The following MXML code example shows how a Flex client application can pass XML data that represents a user’s mortgage application to a LiveCycle mortgage application process and start the process.
When the Flex user submits the mortgage application, the LiveCycle process is invoked and populated with the XML data from the Flex application. The XML data passed in the lc.invoke operation matches the structure of the schema defined for the mortgage application process in LiveCycle. The createXML method in the script block of the MXML provides the XML data to the process; it is stored in the variable named xml, which is passed a parameter to the process in the lc.invoke({xmlData: xml}) method. The XML elements in the createXML method are bound to the form fields in which the user enters data, shown after this example.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" creationPolicy="all"
backgroundGradientColors="[#FFFFFF, #FFFFFF]" creationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import flash.net.navigateToURL;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.collections.ArrayCollection;
import mx.rpc.livecycle.JobId;
import mx.rpc.livecycle.JobStatus;
import mx.rpc.livecycle.DocumentReference;
// Holds the job ID returned by LC.JobManager
private var ji:JobId;
private function initApp():void
{
/* var amfChannel:AMFChannel = new AMFChannel(null,
"http://10.60.147.127:9081/remoting/messagebroker/amf");
*/
var amfChannel:AMFChannel = new AMFChannel(null,
"http://10.60.84.33:8080/remoting/messagebroker/amf");
//10.60.84.33:8080
var channelSet:ChannelSet = new ChannelSet();
channelSet.addChannel(amfChannel);
lc.channelSet = channelSet;
jmService.channelSet = channelSet;
}
private function submitApplication():void
{
var xml:XML = createXML();
lc.invoke_Async({xmlData: xml});
}
// Handles async call that invokes the long-lived process
private function resultHandler(event:ResultEvent):void
{
ji = event.result as JobId;
bGetStatus.enabled = true;
jobStatusDisplay.text = "Job Status ID: " + ji.jobId as String;
}
private function getStatus():void
{
jmService.getStatus(ji);
}
private function getStatusHandler(event:ResultEvent):void
{
var res:JobStatus = event.result as JobStatus;
var resInt:int = res.statusCode;
jobStatusDisplay.text = new String(res.toString());
if(res.statusCode == JobStatus.JOB_STATUS_COMPLETED)
{
bGetResponse.enabled = true;
}
}
// Get results (should only be called once you know that the job has completed)
private function getResp():void{
jmService.getResponse(ji);
}
private function getResponseHandler(event:ResultEvent):void
{
var res:Object = event.result;
var docRef:DocumentReference = res["pdfDoc"] as DocumentReference;
//Alert.show(docRef.url);
navigateToURL(new URLRequest(docRef.url as String), "_blank");
}
private function createXML():XML
{
var model:XML =
<mortgageApplication>
<applicant>
<firstName>{applicant.firstName.text}</firstName>
<lastName>{applicant.lastName.text}</lastName>
<daytimePhone>{applicant.daytimePhone.text}</daytimePhone>
<mobilePhone>{applicant.mobilePhone.text}</mobilePhone>
<notifyMobile>{applicant.notifyMobile.selected}
</notifyMobile>
<email>{applicant.email.text}</email>
<usCitizen>{applicant.citizenYes.selected}</usCitizen>
</applicant>
<property>
<address>{property.address.text}</address>
<city>{property.city.text}</city>
<state>{property.stateCB.selectedLabel}</state>
<zip>{property.zip.text}</zip>
<type>
{property.singleFamily.selected?"single family":"condominium"}
</type>
</property>
<mortgage>
<price>{mortgage.price.value}</price>
<downPayment>{mortgage.downPayment.value}</downPayment>
<loanAmount>
{mortgage.price.value - mortgage.downPayment.value}
</loanAmount>
<closingDate>
{mortgage.closingDate.selectedDate}
</closingDate>
</mortgage>
<employment/>
<assets/>
</mortgageApplication>
var jobList:ArrayCollection = employment.jobList;
var length:int = jobList.length;
for (var i:int=0; i<length; i++) {
var job:XML =
<job>
<company>{jobList[i].company}</company>
<startDate>{jobList[i].startDate}</startDate>
<endDate>{jobList[i].endDate}</endDate>
<salary>{jobList[i].salary}</salary>
</job>;
model.employment[0].appendChild(job);
}
var accountList:ArrayCollection = assets.accountList;
length = accountList.length;
for (var j:int=0; j<length; j++) {
var account:XML =
<account>
<bank>{accountList[j].bank}</bank>
<accountId>{accountList[j].accountId}</accountId>
<balance>{accountList[j].balance}</balance>
</account>;
model.assets.appendChild(account);
}
return model;
}
private function faultHandler(event:FaultEvent):void
{
Alert.show(
event.fault.faultString + "\n" +
event.fault.faultCode + "\n" +
event.fault.faultDetail,
"Error");
}
]]>
</mx:Script>
<!-- <mx:Style source="main.css"/> -->
<!-- Declare the RemoteObject and set its destination to the mortgage-app remoting endpoint defined in LiveCycle. -->
<mx:RemoteObject id="lc" destination="mortgage-app"
result="resultHandler(event)" fault="faultHandler(event)"/>
<mx:RemoteObject id="jmService" destination="LC.JobManager" showBusyCursor="true" fault="faultHandler(event)">
<mx:method name="getStatus" result="getStatusHandler(event)"/>
<mx:method name="getResponse" result="getResponseHandler(event)"/>
</mx:RemoteObject>
<mx:Panel title="My Mortgage Application" backgroundAlpha="0.8" backgroundImage="img/background.jpg">
<mx:Accordion width="700" height="550" backgroundAlpha=".8">
<Applicant id="applicant" label="Applicant Information"/>
<Property id="property" label="Property Information"/>
<MortgageInfo id="mortgage" label="Mortgage Information"/>
<Employment id="employment" label="Employment History" />
<Assets id="assets" label="Financial Assets"/>
</mx:Accordion>
<mx:ControlBar bottom="20">
<mx:Button label="Submit Application" icon="@Embed('img/icon_save.png')" click="submitApplication()"/>
<mx:Button label="Get Status" id="bGetStatus" enabled="false" icon="@Embed('img/icon_save.png')" click="getStatus()"/>
<mx:Button label="Get Response" id="bGetResponse" enabled="false" icon="@Embed('img/icon_save.png')" click="getResp()"/>
</mx:ControlBar>
<mx:Text id="jobStatusDisplay" width="300" />
</mx:Panel>
</mx:Application>
The XML elements in the createXML method are bound to the form fields in which the user enters data, such as the following form (contained in another MXML file in the application):
<?xml version="1.0" encoding="utf-8"?>
<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:StringValidator source="{firstName}" property="text"/>
<mx:SocialSecurityValidator source="{ssn}" property="text"/>
<mx:PhoneNumberValidator source="{daytimePhone}" property="text"/>
<mx:PhoneNumberValidator source="{mobilePhone}" property="text"/>
<mx:EmailValidator source="{email}" property="text"/>
<mx:FormItem label="First Name" required="true">
<mx:TextInput id="firstName" width="200"/>
</mx:FormItem>
<mx:FormItem label="Last Name" required="true">
<mx:TextInput id="lastName" width="200"/>
</mx:FormItem>
<mx:Spacer height="12"/>
<mx:FormItem label="Social Security Number" required="true">
<mx:TextInput id="ssn" width="200"/>
</mx:FormItem>
<mx:FormItem label="Daytime Phone Number" paddingTop="12" required="true">
<mx:TextInput id="daytimePhone" width="200"/>
</mx:FormItem>
<mx:FormItem label="Mobile Phone Number">
<mx:TextInput id="mobilePhone" width="200"/>
<mx:HBox horizontalGap="0">
<mx:CheckBox id="notifyMobile"/>
<mx:Text text="Notify me on this number when the status of my mortgage changes" width="200"/>
</mx:HBox>
</mx:FormItem>
<mx:Spacer height="12"/>
<mx:FormItem label="Email Address" required="true">
<mx:TextInput id="email" width="200"/>
</mx:FormItem>
<mx:Spacer height="12"/>
<mx:FormItem label="Are you a US citizen?">
<mx:RadioButton id="citizenYes" label="Yes" selected="true" groupName="citizen"/>
<mx:RadioButton id="citizenNo" label="No" groupName="citizen"/>
</mx:FormItem>
</mx:Form>
For a complete set of form fields, see the Mortgage Loan Application examples in the LiveCycle ES samples directory (once you've installed LiveCycle ES or LiveCycle Data Services ES Express).