AN INTRODUCTION TO INTEGRATING COLDFUSION, COLDSPRING, AND FLEX 3

W
Shared by: gregoria
-
Stats
views:
379
posted:
11/20/2008
language:
English
pages:
29
Document Sample
scope of work template
							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
 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




                       Integrating ColdFusion, ColdSpring, and Flex   2
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
    ◦ mx:RemoteObject component




                            Integrating ColdFusion, ColdSpring, and Flex   3
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




                          Integrating ColdFusion, ColdSpring, and Flex   4
Example Projects
   Example projects
    ◦ Example1NoColdSpring,
      http://www.brucephillips.name/flex/coldspringexa
      mple/example1nocoldspring.zip
    ◦ Example1,
      http://www.brucephillips.name/flex/coldspringexa
      mple/example1.zip
    ◦ Example2,
      http://www.brucephillips.name/flex/coldspringexa
      mple/example2.zip
   Microsoft Access or MySQL Database
    ◦ http://www.brucephillips.name/flex/coldspringexa
      mple/data.zip

                               Integrating ColdFusion, ColdSpring, and Flex   5
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

                               Integrating ColdFusion, ColdSpring, and Flex   6
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)




                       Integrating ColdFusion, ColdSpring, and Flex   7
CFCs Dependencies
   UserService             UserService
                             m_userDAO: UserDAO
    CFC
                             getUserByID()




                            UserDAO
   UserDAO
    CFC                      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
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
                               Integrating ColdFusion, ColdSpring, and Flex   9
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



                           Integrating ColdFusion, ColdSpring, and Flex   10
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

                               Integrating ColdFusion, ColdSpring, and Flex   11
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
    ◦ <cfset
      application.beanFactory.loadBeans(expandPath
      ("services.xml"))/>

                            Integrating ColdFusion, ColdSpring, and Flex   12
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
                                Integrating ColdFusion, ColdSpring, and Flex   13
Services.xml continued
   See 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 a CFC
   Append 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 By
ColdSpring
   When 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 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 isn’t using ColdSpring to
      manage dependencies


                                Integrating ColdFusion, ColdSpring, and Flex   17
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




                        Integrating ColdFusion, ColdSpring, and Flex   18
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 doesn’t exist
    ◦ Need to connect Flex to the UserService CFC
      being managed by ColdSpring

                                   Integrating ColdFusion, ColdSpring, and Flex   19
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
  CFC’s being managed by ColdSpring with
  their dependencies resolved




                      Integrating ColdFusion, ColdSpring, and Flex   20
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

                                Integrating ColdFusion, ColdSpring, and Flex   21
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

                           Integrating ColdFusion, ColdSpring, and Flex   22
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




                     Integrating ColdFusion, ColdSpring, and Flex   23
Connect Flex to The Remote
Façade CFC
 Use 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
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?

                             Integrating ColdFusion, ColdSpring, and Flex   25
Questions?
 This presentation is posted on my blog at
  http://www.brucephillips.name/blog
 My email address is Bruce@Phillips.name




                        Integrating ColdFusion, ColdSpring, and Flex   26
References
1. 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 continued
5. Remote Synthesis Blog, Objects and
   Composition - Connecting To Flex
6. 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
References
9.  Using ColdFusion With Flex 2,
    http://download.macromedia.com/pub/docu
    mentation/en/flex/2/using_cf_with_flex2.pd
    f
10. FuseBox and ColdSpring,
    http://corfield.org/blog/index.cfm/do/blog.e
    ntry/entry/Fusebox_5_and_ColdSpring
11. ColdFusion MX Coding Guidelines - Good
    Practice,
    http://livedocs.adobe.com/wtg/public/codin
    g_standards/goodpractice.html
                          Integrating ColdFusion, ColdSpring, and Flex   29

						
Related docs