Using ColdFusion MX with Flex 2
Page 1: ...Using ColdFusion MX with Flex 2...
Page 2: ...orporated endorses or accepts any responsibility for the content on those third party sites Speech compression and decompression technology licensed from Nellymoser Inc www nellymoser com Sorenson Spa...
Page 3: ...g incoming messages 20 Using session and client variables 21 Authentication 22 Data translation 23 Chapter 3 Use ColdFusion Event Gateway Adapter 25 Set up your development environment 26 Create the F...
Page 4: ...3 About the ColdFusion Extensions for Flex Builder 74 Installing the ColdFusion Extensions for Flex Builder 74 Eclipse RDS Support 75 ColdFusion Flex Application wizard 81 ActionScript to CFC wizard 8...
Page 5: ...the advanced data retrieval features of ColdFusion such as the cfpop cfldap and cfquery tags In addition you can use Flash Remoting Update to create Macromedia Flash Forms and Flash applications that...
Page 6: ...ile which is located in the ColdFusion webroot WEB INF flex directory with the wildcard as the source To use the source attribute in MXML you can use any destination by specifying the source If you sp...
Page 7: ...the destination attribute of the mx RemoteObbject tag to point to the name that you defined in the services config xml file for example mx RemoteObject id a_named_reference_to_use_in_mxml destination...
Page 8: ...ing http request ColdFusion populates the cflogin name and cflogin password variables inside the cflogin tag with these values For more information see the documentation for the cflogin tag Example ap...
Page 9: ...ludes the serverFault and serverResult methods which display an alert box to indicate whether the login was successful or not The MXML file appears as follows xml version 1 0 encoding utf 8 mx Applica...
Page 10: ...TextInput id password text adminpwd mx FormItem mx FormItem direction horizontal mx Button label Login click logIn mx Button label Logout click logOut mx FormItem mx Button label Get Secure Data clic...
Page 11: ...lists the ColdFusion data types and the corresponding ActionScript data type T I P To make communication between the Flex application and the CFC secure you can specify that the AMF channel in the Col...
Page 12: ...12 Using Flash Remoting Update...
Page 13: ...at uses the event gateway You should be familiar with ColdFusion event gateway in ColdFusion MX Developer s Guide This document also assumes that you are familiar with Adobe Flex Data Services Content...
Page 14: ...pplication to the ColdFusion application and then from the ColdFusion application to the Flex application 1 The Flex application generates a message 2 The Flex Message Service passes the message to th...
Page 15: ...gh you can configure an instance of a Flex Messaging event gateway by creating a configuration file which you specify when you create the gateway instance you can also provide the configuration inform...
Page 16: ...g event gateway 1 Copy the following adapter definition section from the sample messaging config xml file to the web application flex messaging service xml file into the adapter section adapter defini...
Page 17: ...10 1 1 1 gatewayhost List the IP addresses of CF machines allowed to send messages to this destination If not set the default is to allow only this computer to connect Do NOT use 127 0 0 1 it must be...
Page 18: ...c HTTP channel channel definition id cf polling amf class mx messaging channels AMFChannel endpoint uri http server name server port context root messagebroker cfamfpolling class flex messaging endpoi...
Page 19: ...ID Correlation identifier of the message Destination Flex destination of the message This is required if it is not specified in the configuration file Headers If the message contains any headers the C...
Page 20: ...comingMessage function of the configured CFC with the following information mapped to the data of the event The incoming message data structure also includes the values of messageID and timeToLive fro...
Page 21: ...te the structure as the following example shows cfset messageheader StructNew cfset messageheader sendto event data headers emailto cfset messageheader sentfrom event data headers emailfrom cfset mess...
Page 22: ...ion accepts messages Also you can specify the allowed IPs for when you send messages from Flex to ColdFusion You do so in the destination definition in the messaging config xml file on the server on w...
Page 23: ...the cflogin tag as follows cfapplication name authenticateuser sessionmanagement yes cflogin cfif isDefined cflogin name or isDefined cflogin password cfloginuser name cflogin name password cflogin p...
Page 24: ...24 Using the Flex Messaging Event Gateway...
Page 25: ...and the Flex Messaging event gateway the sample application lets you enter information in a form in a Flex application The Flex application sends the information through the ColdFusion Event Gateway A...
Page 26: ...are running on localhost 127 0 0 1 on your local computer Because of the way in which the Remote Method Invocation RMI registry is created and maintained Adobe recommends that you start Flex Data Ser...
Page 27: ...un4 servers default samples WEB INF flex folder when you install Flex in the default location 2 Copy the destination section in which id ColdFusionGateway from the sample messaging config xml file to...
Page 28: ...default samples dataservice myapp folder Create the user interface In this section you create the controls to enter information to send an e mail message 1 Add the following MXML code after the mx Ap...
Page 29: ...ges AsyncMessage 3 Save the file Create the Producer and Consumer In this section you declare the variables for the message Producer and the message Consumer 1 Directly below the import statements in...
Page 30: ...ng code public function sendMessage void var msg AsyncMessage new AsyncMessage msg headers gatewayid Flex2CF2 msg body new Object msg body emailto emailto text msg body emailfrom emailfrom text msg bo...
Page 31: ...nsumer public function initApp pro new mx messaging Producer pro destination ColdFusionGateway consumer subscribe public function sendMessage void var msg AsyncMessage new AsyncMessage msg headers gat...
Page 32: ...the Flex application in a structure It then sends an e mail message by using elements of the structure A ColdFusion application can handle data sent from a Flex application in either the header or the...
Page 33: ...n you must set up the testing environment run the Flex application and then view your e mail client to ensure that the application sent the e mail message successfully Set up the testing environment B...
Page 34: ...address is one whose incoming e mail you can check 3 Enter the name of the sender in the From text box 4 Enter the subject in the Subject text box 5 Enter the message in the Message text area 6 Click...
Page 35: ...ce assembler and write and test an application that uses the assembler This chapter assumes that you are familiar with ColdFusion components as well as accessing and using data in ColdFusion applicati...
Page 36: ...he process that Flex and ColdFusion use when a Flex application calls a method in a ColdFusion component 1 A Flash client requests data that is handled by the Flex Data Management Service 2 Flex calls...
Page 37: ...ses the ColdFusion Data Service adapter and Flex Data Service assembler to manage back end database tasks 1 Design your application 2 Configure a destination for the ColdFusion Data Service adapter Fo...
Page 38: ...hannels to use Flex includes a preconfigured channel cf dataservice rtmp The name or path of the assembler CFC The scope which can be application session or request Application specifies that there is...
Page 39: ...F server component samples contact ContactAssembler component Either application or request scope request scope The hostname or IP address of the CF host Optional default is localhost hostname localho...
Page 40: ...larations are ignored for CFC Assemblers with the exception of the fill method settings Method names are fixed fill sync get count No parameters are defined here unlike Java Any arguments provided via...
Page 41: ...id cf polling amf class mx messaging channels AMFChannel endpoint uri http server name server port context root messagebroker cfamfpolling class flex messaging endpoints AMFEndpoint properties serial...
Page 42: ...Service recognizes the methods fill get sync and count The fill method retrieves records from a database and populates an array with the records The get method retrieves a specific record The sync me...
Page 43: ...updated you include a fillContains method in the assembler and set both use fill contains and auto refresh to true in the fill method section of the data management config xml file A sample fill metho...
Page 44: ...0 This is the everything fill cfreturn true cfelseif ArrayLen fillArgs EQ 1 This is a search fill cfset search fillArgs 1 cfset first item getFirstName cfset last item getLastName If the first or last...
Page 45: ...ssword elements as follows destination id cfcontact adapter ref coldfusion dao channels channel ref cf dataservice rtmp channels properties source samples contact ContactAssembler source scope applica...
Page 46: ...ystore to a certificate by using the keytool utility with a command similar to the following keytool export v alias FlexAssembler keystore cf keystore rfc file cf cer 2 Import the certificate into the...
Page 47: ...ore password text box 3 Select the Enable RMI over SSL for Data Management option and then click Submit Changes If you specify an invalid keystore file or password ColdFusion does not enable SSL and d...
Page 48: ...file 5 Copy the files for the Flex Contact sample application to the appropriate folders 6 Run the application Creating the assembler CFC The assembler CFC contains the fill sync get and count methods...
Page 49: ...argument and have a return value of an array The arrray that the sync method accepts contains Java ChangeObjects which Flex creates and documents The sync method appears as follows cffunction name syn...
Page 50: ...contact ContactDAO Create the record create returns with the identity fields set cfset dao create new Set the new version in to the change object cfset co setNewVersion new Mark this change as proces...
Page 51: ...ion name doDelete access private output no cfargument name co required yes hint The change object The record to delete cfset var old co getPreviousVersion cftry cfset dao CreateObject component sample...
Page 52: ...me param type string required no cftry cfset dao CreateObject component samples contact ContactDAO cfif structKeyExists arguments param cfreturn dao count param arguments param cfelse cfreturn dao cou...
Page 53: ...act ContactDAO cfset ret cfset ret dao read id key cfif ArrayLen ret EQ 1 cfreturn ret 1 cfelseif ArrayLen ret GT 1 cfset co fail get returned more than one record when contactId had a value of key cf...
Page 54: ...KeyExists arguments id where contactId cfqueryparam cfsqltype CF_SQL_INTEGER value arguments id cfelseif structKeyExists arguments param Adjust this WHERE clause based on how to filter For example to...
Page 55: ...ce contacts insert into Contacts FirstName LastName Address City State Zip phone values cfqueryparam value localFirstName cfsqltype CF_SQL_VARCHAR cfqueryparam value localLastName cfsqltype CF_SQL_VAR...
Page 56: ...ct cfset var qUpdate cfquery name qUpdate datasource contacts update Contacts set FirstName cfqueryparam value arguments Contacts getFirstName cfsqltype CF_SQL_VARCHAR LastName cfqueryparam value argu...
Page 57: ...name id required false cfargument name param required false cfset var qRead cfquery name qRead datasource contacts select COUNT as totalRecords from Contacts cfif structKeyExists arguments id where co...
Page 58: ...string default cfproperty name lastName type string default cfproperty name address type string default cfproperty name city type string default cfproperty name state type string default cfproperty na...
Page 59: ...me output false access public returntype void cfargument name val required true cfset this lastName arguments val cffunction cffunction name getaddress output false access public returntype any cfretu...
Page 60: ...rn this phone cffunction cffunction name setphone output false access public returntype void cfargument name val required true cfset this phone arguments val cffunction cfcomponent Specifying the dest...
Page 61: ...sion server component samples contact ContactAssembler component The hostname or IP address of the ColdFusion host hostname localhost hostname The resolution rules and access level of the CFC access A...
Page 62: ...TheFlex Contact Manager application includes the following files contactmgr mxml hourglass mxml mini mxml mini mxml wait png All of the files except contact as should be in the dataservice folder of...
Page 63: ...lections ArrayCollection import mx data Conflict import mx data Conflicts import mx data DataService import mx data IManaged import mx data events import mx messaging events import mx rpc import mx rp...
Page 64: ...kind fill contacts length 0 dg selectedIndex 0 contact contacts 0 private function faultHandler event DataServiceFaultEvent void Hourglass remove Alert show event fault faultstring Error if event item...
Page 65: ...rivate function deleteContact void Hourglass show this var index int dg selectedIndex ds deleteItem contact var token AsyncToken ds commit token kind delete token index index private function searchCo...
Page 66: ...taGrid mx ControlBar mx TextInput id searchText width 100 enter searchContacts mx Button label Search click searchContacts width 60 mx ControlBar mx Panel mx Panel title Details dg selectedIndex 1 con...
Page 67: ...x 1 width 60 mx ControlBar mx Panel mx HDividedBox mx Application hourglass mxml The hourglass mxml file contains the following xml version 1 0 encoding utf 8 Copyright C 2003 2006 Adobe Macromedia So...
Page 68: ...i mxml The mini mxml file contains the following xml version 1 0 encoding utf 8 Copyright C 2003 2006 Adobe Macromedia Software LLC and its licensors All Rights Reserved The following is Sample Code a...
Page 69: ...dataField phone headerText Phone mx columns mx DataGrid mx Panel mx Script CDATA import mx controls Alert import mx data Conflict import mx data Conflicts import mx data events DataConflictEvent impor...
Page 70: ...ent accompanying this product If you have received this file from a source other than Adobe then your use modification or distribution of it requires the prior written permission of Adobe package samp...
Page 71: ...Example application 71 wait png The wait png file appears as follows...
Page 72: ...72 Using the Flex Data Service Assembler...
Page 73: ...ion Extensions for Flex Builder you should be familiar with ColdFusion components as well as accessing and using data in ColdFusion applications You should also be familiar with Adobe Flex Builder Con...
Page 74: ...onScript wizard which lets you create an ActionScript file based on a CFC Value Object Services Browser which lets you browse CFCs manage a list of web services and generate the CFML code to invoke a...
Page 75: ...Click Yes to restart Flex Builder 5 When Flex Builder restarts select Software Updates Manage Configuration 6 Select the ColdFusion Flex Builder feature and click Uninstall 7 Click Yes to confirm that...
Page 76: ...n about the context root see Installing and Using ColdFusion MX Password which is the RDS password 4 To remove a server definition select the server and click Remove 5 To test a connection select the...
Page 77: ...lder is similar to the ColdFusion Report Builder Query Builder and the HomeSite Query Builder Button Action Refresh the active RDS server Create a file in the currently selected folder Delete the curr...
Page 78: ...s own tab which means that if you have other documents open the RDS Query Viewer has focus 2 Do one of the following Enter the SQL and double click the field names and table names as appropriate Click...
Page 79: ...and the Properties panel 1 Expand a data source 2 Double click the columns to be named in the SELECT statement As you select columns the Query Builder creates the SELECT statement in the area at the...
Page 80: ...he column in the Properties panel b Click in the Condition cell c Select Group By or the aggregate function such as COUNT 7 Optional To specify SQL manually type the SQL statement in the SQL pane 8 Op...
Page 81: ...ail page The fields to display in each page The fields that connect one page to another In the following example you create an application for an art gallery The first page lists all the artists that...
Page 82: ...d then click Load ColdFusion Flex Application Wizard Settings 6 Click Next 7 Select the RDS server on which you want the application to reside 8 Specify the data source to use The data source is confi...
Page 83: ...l forms should appear indented directly under the related master form in the Navigation Tree panel You drag and drop items to move them in the tree structure 8 Click Next The Project information page...
Page 84: ...ooses the key by default If you create a master page and do not link it to the id property you cannot add it to the site tree under another master page Deselect the Display column for fields that your...
Page 85: ...s 8 To specify the property scope select public or private 9 Click Finish CFC to ActionScript wizard The CFC to ActionScript wizard lets you create an ActionScript file based on a ColdFusion component...
Page 86: ...rimary key value save delete Bean DAO style CRUD CFCs which creates two related CFCs A Bean CFC also called a Value Object which contains the property definitions and get and set methods The DAO CFC w...
Page 87: ...ce Assembler CFCs 10 Enter the names of the CFCs in the appropriate text boxes 11 To create an ActionScript Value Object a Select the Create an ActionScript Value Object in Addition to the CFCs option...
Page 88: ...te A sample element of the list appears as follows The first line of the listing contains the path The second line includes the name of the CFC The next two lines contain the names of the functions in...
Page 89: ...er view 2 Select Add WSDL 3 Enter a valid WSDL URL 4 Click OK To delete a web service from the list 1 Right click in the Services Browser view 2 Select Delete WSDL To invoke a web service in ColdFusio...
Page 90: ...vices 3 Highlight a web service or a method in a web service and right click 4 Select Insert CFInvoke The code that the Service Browser generates appears in the ColdFusion file The following is an exa...