1 / 29

An Introduction to Integrating ColdFusion, ColdSpring, and Flex 3

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.

kenda
Download Presentation

An Introduction to Integrating ColdFusion, ColdSpring, and Flex 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

  5. Example Projects • Example 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/coldspringexample/data.zip Integrating ColdFusion, ColdSpring, and Flex

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

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

  8. CFCs Dependencies UserService m_userDAO: UserDAO getUserByID() UserDAO read() The UserService CFC is dependent upon the UserDAO CFC. It must have an object of type UserDAO. • UserService CFC • UserDAO CFC Integrating ColdFusion, ColdSpring, and Flex

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

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

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

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

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

  14. 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

  15. 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

  16. 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

  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 isn’t using ColdSpring to manage dependencies Integrating ColdFusion, ColdSpring, and Flex

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

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

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

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

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

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

  24. 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

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

  26. 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

  27. References ColdSpring Framework, http://www.coldspringframework.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 Integrating ColdFusion, ColdSpring, and Flex

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

  29. References Using ColdFusion With Flex 2, http://download.macromedia.com/pub/documentation/en/flex/2/using_cf_with_flex2.pdf FuseBox and ColdSpring, http://corfield.org/blog/index.cfm/do/blog.entry/entry/Fusebox_5_and_ColdSpring ColdFusion MX Coding Guidelines - Good Practice, http://livedocs.adobe.com/wtg/public/coding_standards/goodpractice.html Integrating ColdFusion, ColdSpring, and Flex

More Related