An Introduction to Integrating ColdFusion, ColdSpring, and Flex 3 - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

An Introduction to Integrating ColdFusion, ColdSpring, and Flex 3

Description:

Download the zipped data file and unzip it. ... Unzip it to your web root. Should now have a ColdSpring folder under your web root ... – PowerPoint PPT presentation

Number of Views:170
Avg rating:3.0/5.0
Slides: 30
Provided by: BrucePh7
Category:

less

Transcript and Presenter's Notes

Title: An Introduction to Integrating ColdFusion, ColdSpring, and Flex 3


1
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.brucephil
    lips.name/blog

2
Goals
  • Learn how to use ColdSpring to manage
    dependencies between ColdFusion Components (CFCs)
  • Learn how to use ColdSpring to automatically
    create CFCs that Flex can use

3
What Do You Need To Already Know?
  • How to create and use CFCs
  • Service, Gateway, DAO, Bean CFCs
  • A basic understanding of how to create a Flex
    application that uses ColdFusion and remote
    object services
  • mxRemoteObject component

4
What Do You Need To Have?
  • ColdFusion version 7.0.2 or higher
  • ColdSpring 1.0 final release (see ref. 1)
  • Flex Builder 2 or 3

5
Example Projects
  • Example projects
  • Example1NoColdSpring, http//www.brucephillips.nam
    e/flex/coldspringexample/example1nocoldspring.zip
  • Example1, http//www.brucephillips.name/flex/colds
    pringexample/example1.zip
  • Example2, http//www.brucephillips.name/flex/colds
    pringexample/example2.zip
  • Microsoft Access or MySQL Database
  • http//www.brucephillips.name/flex/coldspringexamp
    le/data.zip

6
Setup Example Projects
  • Download the zipped project files
  • Import 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

7
ColdSpring
  • Developed 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)

8
CFCs Dependencies
  • UserService 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.
9
Managing CFC Dependencies Without Using ColdSpring
  • Hardwire the dependencies
  • Show Code example (example1NoColdSpring)
  • Within the UserService CFC create an object of
    the UserDAO CFC
  • On 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

10
Get and Setup ColdSpring
  • Download ColdSpring zipped file (ref. 1)
  • Unzip it to your web root
  • Should now have a ColdSpring folder under your
    web root
  • C\ColdFusion8\wwwroot\coldspring
  • Under the coldspring folder are an examples and a
    docs folder

11
Integrating ColdSpring and A ColdFusion
Application
  • Add 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

12
Provide ColdSpring Your Applications
Configuration Parameters
  • ColdSpring 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
  • ltcfset application.beanFactory.loadBeans(expandPat
    h("services.xml"))/gt

13
Services.xml Telling ColdSpring About Your CFCs
and Dependencies
  • See example1 - services.xml
  • CFCs are defined in the XML by the bean element
  • The bean child element named property defines
    dependencies
  • See bean definition with an id of userService
  • For each property we need a comparable set method
    in the CFC
  • See example1 - UserService CFC setUserDAO method

14
Services.xml continued
  • See the bean definition with an id of userDAO
  • Can also pass values to a CFCs 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

15
Changing Services.xml or a CFC
  • Append reloadApp1 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

16
Using CFCs Being Managed By ColdSpring
  • When you need an object of a CFC being managed by
    ColdSpring use the BeanFactorys getBean method
  • See example1 index.cfm

17
CFCs Are Ignorant of ColdSpring
  • The 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 isnt using ColdSpring to manage dependencies

18
ColdSpring and ColdFusion Frameworks
  • Most major ColdFusion Frameworks (Mach-II,
    Model-Glue, FuseBox) include the ability to
    integrate ColdSpring
  • Complex applications often use ColdSpring and a
    framework together

19
ColdSpring and Flex
  • If 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 doesnt exist
  • Need to connect Flex to the UserService CFC being
    managed by ColdSpring

20
ColdSpring and Remoting
  • ColdSpring can automatically create a remote
    façade CFC that we can connect to with Flex
  • The remote façade CFC will expose any CFCs being
    managed by ColdSpring with their dependencies
    resolved

21
Creating A Remote Façade CFC
  • Add 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

22
Have ColdSpring Create The Remote Façade CFC
  • Modify 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/cfc
  • The first time the application runs ColdSpring
    will create the remote façade CFC
  • In this example UserServiceRemote CFC

23
Remote Façade CFC
  • See example2 UserServiceRemote CFC (in model
    folder)
  • Note the function getUserByID
  • The remote façade CFC can be used by Flex or Ajax
    applications

24
Connect Flex to The Remote Façade CFC
  • Use the mxRemoteObject 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

25
Cautions
  • Make 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?

26
Questions?
  • This presentation is posted on my blog at
    http//www.brucephillips.name/blog
  • My email address is Bruce_at_Phillips.name

27
References
  • ColdSpring Framework, http//www.coldspringframewo
    rk.org/
  • ColdFusion Developer's Journal Special
    "Frameworks" Focus Issue ColdSpring
    http//coldfusion.sys-con.com/read/176181.htm
  • The Blog of Andy Jarrett, ColdSpring and
    Dependency Injection for the beginner part 1
  • ColdSpring Online Documentation,
    http//www.coldspringframework.org/docs

28
References continued
  • Remote Synthesis Blog, Objects and Composition -
    Connecting To Flex
  • Developing With ColdSpring, ColdSpring and
    Remoting
  • Flex 3 Remote Object Components,
    http//livedocs.adobe.com/flex/3/html/data_intro_2
    .html
  • Flex 3 Using RemoteObject Components,
    http//livedocs.adobe.com/flex/3/html/data_access_
    4.html

29
References
  • Using ColdFusion With Flex 2, http//download.macr
    omedia.com/pub/documentation/en/flex/2/using_cf_wi
    th_flex2.pdf
  • FuseBox and ColdSpring, http//corfield.org/blog/i
    ndex.cfm/do/blog.entry/entry/Fusebox_5_and_ColdSpr
    ing
  • ColdFusion MX Coding Guidelines - Good Practice,
    http//livedocs.adobe.com/wtg/public/coding_standa
    rds/goodpractice.html
Write a Comment
User Comments (0)
About PowerShow.com