Upload
kenda
View
39
Download
0
Embed Size (px)
DESCRIPTION
An Introduction to Integrating ColdFusion, ColdSpring, and Flex 3. A Presentation to the Kansas City Adobe RIA User Group March 25, 2008 Download this presentation at http://www.brucephillips.name/blog. Goals. - PowerPoint PPT Presentation
Citation preview
AN INTRODUCTION TO AN INTRODUCTION TO INTEGRATING INTEGRATING COLDFUSION, COLDFUSION, COLDSPRING, AND FLEX COLDSPRING, AND FLEX 33
A Presentation to the Kansas City Adobe RIA User GroupMarch 25, 2008Download this presentation at http://www.brucephillips.name/blog
GoalsGoalsLearn how to use ColdSpring to
manage dependencies between ColdFusion Components (CFCs)
Learn how to use ColdSpring to automatically create CFCs that Flex can use
Integrating ColdFusion, ColdSpring, and Flex 2
What Do You Need To What Do You Need To Already Know?Already Know?How to create and use CFCs
◦Service, Gateway, DAO, Bean CFCsA basic understanding of how to
create a Flex application that uses ColdFusion and remote object services◦mx:RemoteObject component
Integrating ColdFusion, ColdSpring, and Flex 3
What Do You Need To What Do You Need To Have?Have?ColdFusion version 7.0.2 or
higherColdSpring 1.0 final release (see
ref. 1)Flex Builder 2 or 3
Integrating ColdFusion, ColdSpring, and Flex 4
Example ProjectsExample ProjectsExample projects
◦Example1NoColdSpring, http://www.brucephillips.name/flex/coldspringexample/example1nocoldspring.zip
◦Example1, http://www.brucephillips.name/flex/coldspringexample/example1.zip
◦Example2, http://www.brucephillips.name/flex/coldspringexample/example2.zip
Microsoft Access or MySQL Database◦http://www.brucephillips.name/flex/colds
pringexample/data.zip 5
Integrating ColdFusion, ColdSpring, and Flex
Setup Example ProjectsSetup Example ProjectsDownload the zipped project filesImport into Flex Builder
◦File – Import – Other – General – Archive File
Download the zipped data file and unzip it. Use justCSdb.sql to create a MySQL database or use the justCSdb.mdb Microsoft Access database
Create a data source in ColdFusion administrator named justCSdbMySQL that refers to the database
6Integrating ColdFusion, ColdSpring, and Flex
ColdSpringColdSpringDeveloped by Dave Ross
(www.d-ross.org) and several others
Manages the dependencies between CFCs
Read an Introduction to ColdSpring and ColdSpring and Dependency Injection for the beginner part 1 (ref. 3 and 4)
Integrating ColdFusion, ColdSpring, and Flex 7
CFCs DependenciesCFCs DependenciesUserServic
e CFC
UserDAO CFC
UserService m_userDAO: UserDAO
getUserByID()
UserDAO read()
The UserService CFC is dependent upon the UserDAO CFC. It must have an object of type UserDAO.
Integrating ColdFusion, ColdSpring, and Flex 8
Managing CFC Dependencies Managing CFC Dependencies Without Using ColdSpringWithout Using ColdSpringHardwire the dependenciesShow Code example
(example1NoColdSpring)◦Within the UserService CFC create an
object of the UserDAO CFCOn large projects with lots of
Service, Gateway, DAO, Bean CFCs that are dependent on each other, hardwiring these dependencies can be cumbersome and time consuming to manage
Integrating ColdFusion, ColdSpring, and Flex 9
Get and Setup ColdSpringGet and Setup ColdSpringDownload ColdSpring zipped file
(ref. 1)Unzip it to your web rootShould now have a ColdSpring
folder under your web root◦C:\ColdFusion8\wwwroot\coldspring
Under the coldspring folder are an examples and a docs folder
Integrating ColdFusion, ColdSpring, and Flex 10
Integrating ColdSpring and A Integrating ColdSpring and A ColdFusion ApplicationColdFusion ApplicationAdd code to Application.cfm (or
Application.cfc) to create the ColdSpring BeanFactory object◦A bean factory is a container that
holds all of your CFC objects◦The ColdSpring BeanFactory object is
stored in application scope◦See example1 – Application.cfm◦See example1 – Application.cfc
Integrating ColdFusion, ColdSpring, and Flex 11
Provide ColdSpring Your Provide ColdSpring Your Applications Configuration Applications Configuration ParametersParametersColdSpring reads an XML file that
describes the CFCs, their dependencies, and any additional properties for your application
This line in Application.cfm/cfc reads the configuration XML file◦<cfset
application.beanFactory.loadBeans(expandPath("services.xml"))/>
Integrating ColdFusion, ColdSpring, and Flex 12
Services.xml – Telling Services.xml – Telling ColdSpring About Your CFCs ColdSpring About Your CFCs and Dependenciesand DependenciesSee example1 - services.xmlCFCs are defined in the XML by the
bean elementThe bean child element named
property defines dependencies◦See bean definition with an id of
userServiceFor each property we need a
comparable set method in the CFC◦See example1 - UserService CFC
setUserDAO methodIntegrating ColdFusion, ColdSpring, and Flex 13
Services.xml continuedServices.xml continuedSee the bean definition with an id
of userDAO◦Can also pass values to a CFC’s init
method using the constructor-arg child element of the bean element See init method for the UserDAO CFC and
note the argument named dsn
Integrating ColdFusion, ColdSpring, and Flex 14
Changing Services.xml or Changing Services.xml or a CFCa CFCAppend reloadApp=1 to the
index.cfm URL◦See example1 - Application.cfm◦See example1 – Application.cfc
(onRequestStart function)Forces the BeanFactory to be
recreated and ColdSpring to read the services.xml file
Integrating ColdFusion, ColdSpring, and Flex 15
Using CFCs Being Managed Using CFCs Being Managed By ColdSpringBy ColdSpringWhen you need an object of a
CFC being managed by ColdSpring use the BeanFactory’s getBean method◦See example1 – index.cfm
Integrating ColdFusion, ColdSpring, and Flex 16
CFCs Are Ignorant of CFCs Are Ignorant of ColdSpringColdSpringThe UserDAO and UserService
CFCs are ignorant of ColdSpring◦ColdSpring makes has no
requirements except that your CFCs have an init method Using an init method as a pseudo-
constructor is a ColdFusion best practice (ref. 11)
◦These CFCs could easily be used in an application that isn’t using ColdSpring to manage dependencies
Integrating ColdFusion, ColdSpring, and Flex 17
ColdSpring and ColdFusion ColdSpring and ColdFusion FrameworksFrameworksMost major ColdFusion
Frameworks (Mach-II, Model-Glue, FuseBox) include the ability to integrate ColdSpring
Complex applications often use ColdSpring and a framework together
Integrating ColdFusion, ColdSpring, and Flex 18
ColdSpring and FlexColdSpring and FlexIf ColdSpring is managing the
dependencies between CFCs how can we use those same CFCs with Flex?◦Cannot call the UserService CFC directly
from Flex because its dependencies have not been resolved See example2 – UserService CFC -
getUserByID method Call from Flex will fail because
variables.m_userDAO object doesn’t exist◦Need to connect Flex to the UserService
CFC being managed by ColdSpringIntegrating ColdFusion, ColdSpring, and Flex 19
ColdSpring and RemotingColdSpring and RemotingColdSpring can automatically
create a remote façade CFC that we can connect to with Flex
The remote façade CFC will expose any CFC’s being managed by ColdSpring with their dependencies resolved
Integrating ColdFusion, ColdSpring, and Flex 20
Creating A Remote Façade Creating A Remote Façade CFCCFCAdd a bean element to the
Services.xml configuration file◦class attribute value should be
RemoteFactoryBean◦See example2 – services.xml
Specify the target (the CFC to create a remote façade for)
Specify the name of the remote CFC Specify where to write the remote CFC Specify the methods to expose
Integrating ColdFusion, ColdSpring, and Flex 21
Have ColdSpring Create The Have ColdSpring Create The Remote Façade CFCRemote Façade CFCModify the Application.cfm so that
when ColdSpring finishes processing the configuration XML file it will create the remote CFC object in application scope
See example2 – Application.cfm/cfcThe first time the application runs
ColdSpring will create the remote façade CFC◦In this example UserServiceRemote CFC
Integrating ColdFusion, ColdSpring, and Flex 22
Remote Façade CFCRemote Façade CFCSee example2 –
UserServiceRemote CFC (in model folder)
Note the function getUserByIDThe remote façade CFC can be
used by Flex or Ajax applications
Integrating ColdFusion, ColdSpring, and Flex 23
Connect Flex to The Remote Connect Flex to The Remote Façade CFCFaçade CFCUse the mx:RemoteObject component
to connect Flex to the Remote Façade CFC
See references 7, 8, and 9 for how to connect Flex to ColdFusion CFCs
See example2 – example2.mxml (in src folder)◦Note Flex is connecting to the
UserServiceRemote CFC◦Should be able to run example2 Flex
project, click on the Test Connection button, and get Bruce Phillips back from the ColdFusion CFC
Integrating ColdFusion, ColdSpring, and Flex 24
CautionsCautionsMake sure the remote façade CFC
exists (has been created by ColdSpring) before trying to connect to it using Flex
Research how to integrate Flex into ColdFusion applications that use a framework (Mach-II, Model-Glue, FuseBox) combined with ColdSpring◦How does the framework integrate
ColdSpring and can ColdSpring still create remote façade CFCs?
Integrating ColdFusion, ColdSpring, and Flex 25
Questions?Questions?This presentation is posted on my
blog at http://www.brucephillips.name/blog
My email address is [email protected]
Integrating ColdFusion, ColdSpring, and Flex 26
ReferencesReferences1. ColdSpring Framework,
http://www.coldspringframework.org/
2. ColdFusion Developer's Journal Special "Frameworks" Focus Issue: ColdSpring; http://coldfusion.sys-con.com/read/176181.htm
3. The Blog of Andy Jarrett, ColdSpring and Dependency Injection for the beginner part 1
4. ColdSpring Online Documentation, http://www.coldspringframework.org/docs
Integrating ColdFusion, ColdSpring, and Flex 27
References continuedReferences continued5. Remote Synthesis Blog, Objects and
Composition - Connecting To Flex6. Developing With ColdSpring,
ColdSpring and Remoting 7. Flex 3 Remote Object Components,
http://livedocs.adobe.com/flex/3/html/data_intro_2.html
8. Flex 3 Using RemoteObject Components, http://livedocs.adobe.com/flex/3/html/data_access_4.html
Integrating ColdFusion, ColdSpring, and Flex 28
ReferencesReferences9. Using ColdFusion With Flex 2,
http://download.macromedia.com/pub/documentation/en/flex/2/using_cf_with_flex2.pdf
10.FuseBox and ColdSpring, http://corfield.org/blog/index.cfm/do/blog.entry/entry/Fusebox_5_and_ColdSpring
11.ColdFusion MX Coding Guidelines - Good Practice, http://livedocs.adobe.com/wtg/public/coding_standards/goodpractice.html
Integrating ColdFusion, ColdSpring, and Flex 29