9 Replies Latest reply on Feb 2, 2008 7:14 AM by DannyZ

    FB3/CF8 DataService Does Nothing

    craigkaminsky Level 3
      I have a "real" application that I, very much, need to use data management (returning 10,000s of records from the DB to a data grid) but cannot make it happen.

      To get my head around LCDS and Flex 3, I setup a new project (following the tips in CF8 WACK volume 2, chapter 36). I am using FB 3 (Beta 3) and CF8 on Mac OS X 10.5.1. When I installed CF8 on Leopard, I did tell it to install LCDS.

      In my data-management-config.xml file I added the following destination:
      <destination id="SFA_Individual">
      <adapter ref="coldfusion-dao" />
      <channels>
      <channel ref="cf-dataservice-rtmp"/>
      <channel ref="cf-polling-amf" />
      </channels>
      <properties>
      <component>aems.com.cf.individual.IndividualAssembler</component>
      <scope>application</scope>
      <metadata>
      <identity property="IND_ID" />
      </metadata>
      </properties>
      </destination>

      In my services-config.xml, I added the following (well, uncommented it):
      <channel-definition id="cf-dataservice-rtmp" class="mx.messaging.channels.RTMPChannel">
      <endpoint uri="rtmp://{server.name}:2048" class="flex.messaging.endpoints.RTMPEndpoint"/>
      <properties>
      <idle-timeout-minutes>20</idle-timeout-minutes>
      <serialization>
      <instantiate-types>false</instantiate-types>
      </serialization>
      </properties>
      </channel-definition>

      I have one MXML file in my application:
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical">
      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      [Bindable]
      private var results:ArrayCollection;

      ]]>
      </mx:Script>
      <mx:DataService id="ds" destination="SFA_Individual" autoCommit="false" autoMerge="true" />
      <mx:DataGrid id="dg" dataProvider="{this.results}">
      <mx:columns>
      <mx:DataGridColumn headerText="First Name" dataField="IND_Fname" />
      <mx:DataGridColumn headerText="Last Name" dataField="IND_Lname" />
      </mx:columns>
      </mx:DataGrid>
      <mx:Button id="btn" label="Get Individuals" click="this.ds.fill(results)" />
      </mx:Application>

      When I click the button, nothing happens. No errors and no response from the server. I also tried the same code on a PC (CF8, FB3 Beta 3) with the same results.

      Could someone please help me understand what I am missing? I would really appreciate any help.

      Thank you!
      Craig
        • 1. Re: FB3/CF8 DataService Does Nothing
          ethompsonARA
          Not sure if this helps, but I noticed that DataService is no longer included in the API with Flex 3. The Flex 2 API has it, however. In fact, the entire mx.data package is not there.
          • 2. Re: FB3/CF8 DataService Does Nothing
            craigkaminsky Level 3
            Thanks for replying. I did notice that as well when searching but wasn't sure if it was an oversight since we were dealing with beta documentation or something bigger. I did find the package and details in the LiveCycle documentation for 2.5 (cannot find the link offhand). Not sure how that relates. Again, thanks for replying!
            • 3. Re: FB3/CF8 DataService Does Nothing
              ethompsonARA Level 1
              Does your application compile without errors? When I try to use the tag, the type cannot be found. I also tried it in ActionScript, with no such luck.
              • 4. Re: FB3/CF8 DataService Does Nothing
                craigkaminsky Level 3
                Sadly, no. It did at first but that was because I had a [bleeping] typo in my data-management-config.xml file (apparently coldfusoin-dao doesn't work!). Once I fixed that, it would compile and everything in the application runs -- but the mx:DataService tag never returns data. It does appear that it is firing (it's called from the component's creationComplete event) but not returning any data.

                I get the same results on an IIS 6 machine (with CF8) and a Mac with CF8 installed atop JRun.
                • 5. Re: FB3/CF8 DataService Does Nothing
                  ethompsonARA Level 1
                  So your compiler finds a DataService type? Is there a flex library for LCDS?

                  I had been trying to get Hibernate to work with BlazeDS, but all of the examples I could find on how Flex can interface with Hibernate were done with LCDS and Flex 2. The tutorials used the DataService element, which I could not find in Flex 3 beta 3, so I had to find a different route.

                  In my research to find out why I couldn't use the tag, I couldn't find any indication that DataService definitely is or is not part of Flex 3.
                  • 6. Re: FB3/CF8 DataService Does Nothing
                    craigkaminsky Level 3
                    It does/did. In fact, I just got it working on my Mac dev environment (kept tweaking and messing with the services-config.xml and data-management-config.xml files and finally got it going locally. Still won't work on my production server.

                    I downloaded the LCDS Dev Guide and it has the mx:DataService tag (and corresponding classes) in it. In this guide, there is a section for "Creating a DataService Component" that begins on page 158 of the PDF.

                    If you go here: http://www.adobe.com/support/documentation/en/flex/ you can download the LCDS ES Developer's Guide (at the bottom of the page). It has the document I mention above...or I could make it easier and just post the link to the guide (duh)
                    http://help.adobe.com/en_US/livecycle/es/lcds_dev_guide.pdf

                    • 7. Re: FB3/CF8 DataService Does Nothing
                      DannyZ
                      Part one:

                      Craig,
                      I spent a great deal of time with this issue. It's fairly straight forward once you understand how Adobe's integrated the two products (LCDS and CF8) and how Flexbuilder 3.0 references &quot;dataservices&quot;

                      Background - Since Adobe's re-branded FDS --&gt; LCDS and then split out the remoting and messaging into &quot;Blaze&quot; It's been confusing -- So I'll refer to the portion of the technology simply as &quot;Dataservice&quot;

                      Think of Dataservice as the Flex framework that works in conjuction with a server backend. That backend can be Coldfusion with LCDS pre-Installed or Coldfusion (TIGHT) and a Stand Alone Version of LCDS 2.5,(SA) express or otherwise) The SA version is clearly aimed at JAVA developers, as the samples and 30 minute test drive is specific java , not CF. I'm told it's possible to configure the SA to communicate with CF8, vs java; but weeks of messing and frustration around has proven otherwise.

                      This is the main confusion for most since the DEV NET articles thus far decribe configuration for the SA product.

                      The problem is this, if you've installed CF8 and checked the option to install LCDS as well then your config is tightly integrated. Thus with the CF8 integrated install version Out ot the box, you've got LCDS services for ColdFusion 8.

                      My suggestion is to work with the integrated version bundled with CF8. If you didn't install it with CF8, re-run the installation (pain but it will save you headache later)


                      By default on windows CF installs and sets up the CF webroot here : C:\ColdFusion8\wwwroot

                      Flexbuilder's Project Wizard will create the necessary references if you check ColdFusion, and LCDS as the server tech when you initally create a project. If you've done a remoting project then you'll be familiar with the -services compiler option. The wizard creates both the -services statement and includes the fds.swc (they didn't rename it)

                      Run the new project wizard: choose CF and LCDS...
                      then when promted about server locations:

                      Flexbuilder's new project wizard is going to ask where CF SERVER is installed here you need to point to the CF root.

                      Server location Stand-alone: &quot;Use Default Location for Coldfusion Server&quot;
                      Uncheck &quot;use coldfusion web server&quot;
                      Instead set the location of the &quot;WEB&quot; server to C:\inetpub\wwwroot\ - your webservers root.


                      One you create the project: verify the fds.swc and the compiler statement:

                      -services &quot;C:\ColdFusion8\wwwroot\WEB-INF\flex\services-config.xml&quot; -locale en_US

                      Note it's pointing to the &quot;services-config.xml&quot; in your {CFwwwROOT}/web-inf/flex folder. You may be using another webserver (iis in my case) don't let that fool you. The config in the CFroot is WEB-INF\flex folder is the right location. You will however deploy your flex project and cfc's to folders on your webserver's root. (Confused yet?)

                      Update the services-conf.xml to include the new channels:

                      You will need to modify this file (add CHANNELS for dataservice and polling references) and add a second file data-management-config.xml to contain your projects &quot;destinations&quot;. You can also use includes and another file for each project.

                      In services-config.xml:
                      make sure you have a reference like this: between the channel tags.

                      &lt;!-- CF Based Endpoints --&gt;
                      &lt;channel-definition id=&quot;my-cfamf&quot; class=&quot;mx.messaging.channels.AMFChannel&quot;&gt;
                      &lt;endpoint uri=&quot; http://{server.name}:{server.port}{context.root}/flex2gateway/&quot; class=&quot;flex.messaging.endpoints.AMFEndpoint&quot;/&gt;
                      &lt;properties&gt;
                      &lt;polling-enabled&gt;false&lt;/polling-enabled&gt;
                      &lt;serialization&gt;
                      &lt;instantiate-types&gt;false&lt;/instantiate-types&gt;
                      &lt;/serialization&gt;
                      &lt;/properties&gt;
                      &lt;/channel-definition&gt;

                      &lt;!-- ColdFusion specific RTMP channel --&gt;
                      &lt;channel-definition id=&quot;cf-dataservice-rtmp&quot; class=&quot;mx.messaging.channels.RTMPChannel&quot;&gt;
                      &lt;endpoint url=&quot;rtmp://{server.name}:2048&quot; class=&quot;flex.messaging.endpoints.RTMPEndpoint&quot;/&gt;
                      &lt;properties&gt;
                      &lt;idle-timeout-minutes&gt;0&lt;/idle-timeout-minutes&gt;
                      &lt;serialization&gt;
                      &lt;!-- This must be turned off for any CF channel --&gt;
                      &lt;instantiate-types&gt;false&lt;/instantiate-types&gt;
                      &lt;/serialization&gt;
                      &lt;/properties&gt;

                      This creates the channels for Dataservice (handles the Db connections) and CFPolling (polls the clients looking for changes)

                      TO BE CONTINUED
                      • 8. Re: FB3/CF8 DataService Does Nothing
                        DannyZ Level 1
                        Part TWO:

                        Next verify you have Adapter for CF and also create a Destination in the data-management-config.xml --


                        &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
                        &lt;service id=&quot;data-service&quot;
                        class=&quot;flex.data.DataService&quot;
                        messageTypes=&quot;flex.data.messages.DataMessage&quot;&gt;

                        &lt;adapters&gt;
                        &lt;adapter-definition id=&quot;coldfusion-dao&quot; class=&quot;coldfusion.flex.CFDataServicesAdapter&quot; default=&quot;true&quot;/&gt;
                        &lt;/adapters&gt;

                        &lt;destination id=&quot;cfcontact&quot;&gt;
                        &lt;adapter ref=&quot;coldfusion-dao&quot;/&gt;
                        &lt;channels&gt;
                        &lt;channel ref=&quot;cf-dataservice-rtmp&quot;/&gt;
                        &lt;channel ref=&quot;cf-polling-amf&quot;/&gt;
                        &lt;/channels&gt;
                        &lt;properties&gt;
                        &lt;component&gt;samples.contact.components.ContactAssembler&lt;/component&gt;
                        &lt;scope&gt;request&lt;/scope&gt;
                        &lt;metadata&gt;
                        &lt;identity property=&quot;contactId&quot;/&gt;
                        &lt;/metadata&gt;
                        &lt;/properties&gt;
                        &lt;/destination&gt;
                        &lt;/destination&gt;
                        &lt;/service&gt;

                        &gt;&gt;&gt;&gt;
                        &lt;destination id=&quot;cfcontact&quot;&gt;
                        is the id you'll reference as the &quot;destination&quot; for the dataservice tag in your mxml.


                        &gt;&gt;&gt;&gt;&gt;&gt;&gt;
                        &lt;component&gt;samples.contact.components.ContactAssembler&lt;/component&gt;
                        is the dot path notation to the &quot;assembler&quot; cfc --- this is from your webserver's root...

                        http://localhost/samples/contact/components/ContactAssembler.cfc

                        &gt;&gt;&gt;&gt;&gt;&gt; &lt;metadata&gt;
                        &lt;identity property=&quot;contactId&quot;/&gt;
                        &lt;/metadata&gt;
                        identity property is your Table's unique ID (Primary key)

                        Almost there... Once you've set up the configs (you'll go back and forth as you add more tables and assemblers)

                        You may also need to add a CF mapping the the base project folder (samples in this case) so CF can find the assembler component.

                        Finally back in Flex Builder
                        DBL check your project settings:
                        You'll output or deploy the project to your web root
                        C:\inetpub\wwwroot\samples\contact

                        The &quot;flex server&quot; is your webserver's root -- not LCDS or CFwwwroot - since the webserver handles the reqests and passes it off to cf8 and LCDS tranparently.
                        Flex Server:
                        ROOT Folder: C:\inetpub\wwwroot\
                        Root URL : http://localhost/

                        Generate your Assembler, DAO and Vo files. Sounds more complecated than it is. In flexbuilder open the RDS Dataview panel and browse to a table, right click and create CFC's --

                        The wizard generates Assembler, DAO and Vo cfc's and the AS class (vo) for your table. The assembler is the gateway script that calls to vo and dao's.

                        CFC folder is where you want to save the files: same as the deployment location:
                        samples/contact/components (mapped folder/project folder/component dir)

                        CFC package name is the same dot path notation to your cfc:
                        samples.contact.components

                        CFC type is LCDS Assembler

                        Leave the default names for the cfcs

                        Tick Generate AS class
                        AS folder is folder path to your AS class /contacts/src/com/contact/ (you may want to determine a custom package path like com.contact and name the AS accordingly

                        AS Class name is the class package path: com.contact


                        Finally start simple with a test page that fills a grid.



                        &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
                        &lt;!--
                        ////////////////////////////////////////////////////////////////////////////////
                        //
                        // Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its licensors.
                        // All Rights Reserved.
                        // The following is Sample Code and is subject to all restrictions on such code
                        // as contained in the End User License Agreement 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.
                        //
                        ////////////////////////////////////////////////////////////////////////////////
                        --&gt;
                        &lt;mx:Application xmlns:mx=&quot; http://www.adobe.com/2006/mxml&quot; xmlns=&quot;*&quot; creationComplete=&quot;dataService.fill(contacts)&quot;&gt;

                        &lt;mx:ArrayCollection id=&quot;contacts&quot;/&gt;
                        &lt;mx:DataService destination=&quot;cfcontact&quot; id=&quot;dataService&quot; fault=&quot;faultHandler(event)&quot; conflict=&quot;conflictHandler(event)&quot;/&gt;
                        &lt;mx:Panel title=&quot;Contact List&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;
                        &lt;mx:DataGrid id=&quot;dg&quot; dataProvider=&quot;{contacts}&quot; width=&quot;100%&quot; height=&quot;100%&quot; editable=&quot;true&quot;&gt;
                        &lt;mx:columns&gt;
                        &lt;mx:DataGridColumn dataField=&quot;contactId&quot; headerText=&quot;Id&quot; editable=&quot;false&quot;/&gt;
                        &lt;mx:DataGridColumn dataField=&quot;firstName&quot; headerText=&quot;First Name&quot;/&gt;
                        &lt;mx:DataGridColumn dataField=&quot;lastName&quot; headerText=&quot;Last Name&quot;/&gt;
                        &lt;mx:DataGridColumn dataField=&quot;phone&quot; headerText=&quot;Phone&quot;/&gt;
                        &lt;/mx:columns&gt;
                        &lt;/mx:DataGrid&gt;
                        &lt;/mx:Panel&gt;

                        &lt;mx:Script&gt;
                        &lt;![CDATA[
                        import mx.utils.ObjectUtil;
                        import mx.controls.Alert;
                        import mx.data.Conflict;
                        import mx.data.Conflicts;
                        import mx.data.events.DataConflictEvent;
                        import mx.data.events.DataServiceFaultEvent; // DEV net article was incorrect here... use the ds fault
                        import mx.rpc.events.ResultEvent;
                        import mx.rpc.events.FaultEvent;

                        import com.contact.Contact;


                        private static var _link:Contact = null;

                        private function resultHandler(event:ResultEvent):void
                        {
                        // Alert.show(event.toString(), 'Result')
                        trace(ObjectUtil.toString(event));
                        }


                        private function faultHandler(event:DataServiceFaultEvent):void
                        {
                        Alert.show(event.message.toString(), 'Error')
                        trace(ObjectUtil.toString(event));
                        }

                        private function conflictHandler(event:DataConflictEvent):void
                        {
                        var conflicts:Conflicts = dataService.conflicts;
                        var c:Conflict;
                        for (var i:int=0; i&lt;conflicts.length; i++)
                        {
                        c = Conflict(conflicts.getItemAt(i));
                        Alert.show(&quot;Reverting to server value&quot;, &quot;Conflict&quot;);
                        c.acceptServer();
                        }
                        }
                        ]]&gt;
                        &lt;/mx:Script&gt;

                        &lt;/mx:Application&gt;

                        There you have it.... working with Dataservices is very simple, each table or view will need it's own Assembler,DAO, VO and class. You'll use an array collection on the Flex side as a client side container for the data that's returned. As that array collection changes (in the grid here) that inturn calls the dataservice and updates the server side data. If server side changes before you commit a change in the client it generates a conflict event, you'll need to handle that in Flex. The polling piece keeps all flex clients in sync.

                        I hope this exhaustive post helps you and others get started with dataservices - when it's properly setup, it's very cool. Expect more features from Adobe on this one as they tool up, Again Dataservices is a new direction - it's a both a client and server framework for handling data and sync. Their goal appears to be to create a method of handling the basic DB CRUD opperations between client and server without the need to code the actual transmission of information and updating the db via remoting. Kudos to Adobe for going down this path.

                        The downside is the fact that the re-branding and re-bundling of the product has created a lot of confusion.

                        I hope this adds to your understanding,

                        Dan Zeitman

                        • 9. Re: FB3/CF8 DataService Does Nothing
                          DannyZ Level 1
                          My appoligies, but the forum escaped all the html.... see attached dos.