9 Replies Latest reply on May 22, 2010 11:12 AM by cheftimo

    I am in data-centric hell and want out

    cheftimo Level 2

      I am trying to learn how to work with the new FB 4 data-centric features. So, I have a s:List using TileLayout, I call my ColdFusion service and the product list gets populated. So far so good.

       

      Now, because it’s a big list, I want to filter the data by categories listed in a ComboBox (in Flex 3 projects I have created, my data provider for the list was an ArrayCollection which I could apply filters to, no problems). My question:

       

      What do I filter? When I use the data-centric thing, I can’t figure out exactly what the data provider for the list is, so I can filter that. In fact, ‘dataProvider’ is nowhere to be seen in the generated code. When I trace(myList.dataProvider), it comes up as ‘mx.collections::AsyncListView no list’. I am completely lost here.

       

      Any ideas? If anyone knows of a tutorial that covers something similar, I would love to know about it – I have not been able to find one.

       

      Best regards,

       

      Carlos

        • 1. Re: I am in data-centric hell and want out
          David_F57 Level 5

          hi,

           

          With DCD you get 'flat' code generated for your tables, if you want to do something like what you mention you need to add extra calls to your php services. If you have large amounts of data it is better to filter it at the server end rather than the client, reduced bandwidth etc...

           

          for example if you needed to populate a pick list for category records you would through dcd have a category table(assuming you have the database structured correctly)  DCD would have produced a service getallrecords call for your products, what you need to do is basically copy this service call into a new call lets say 'getProductsbyCategory(catID)'.

           

          Adjust the code to only retrieve the products by catID.

           

          Now you have the needed calls to get what you want. So now the productlist box will bind to the results of the  getProductsbyCategory(catID) which is called by a change to your picklist.

           

           

          David

          • 2. Re: I am in data-centric hell and want out
            cheftimo Level 2

            My amount of data is not that big – it’s about 1300 records, which load in no time.

             

            I don’t know how repeated calls to the server are going to save bandwidth. Also, I thought one of the advantages of RIAs was the ability to work with your data on the client. But those are issues that belong in a separate discussion.

             

            So, for whatever reasons, what I would like to do in this particular project is to bring the data in when the app starts and then work with it on the client during the rest of the session.

             

            Here is an example of the problem I am facing:

             

            The DCD-generated function that populates my list (id=”thumbsList”) is

             

            protected function thumbsList_creationCompleteHandler(event:FlexEvent):void

                              {

                                    getProductsResult.token = tinderbox.getProducts();

                              }

             

            When I put a breakpoint at the end of the function, watching the expression ‘getProductsResult.token’, when I debug, I should be able to see the dataset somewhere, but I cannot find it. I know it’s buried in there somewhere because the list gets populated; but where? I would like to find it and use it as the source for and ArrayCollection or something that I can filter or otherwise manipulate.

             

            If anyone wants to look deeper into this, I can post this test project on the web with ViewSource enabled and provide the URL.

             

            I have asked related questions in past posts and find it odd that nobody seems to know anything about this and the Adobe people stay away from those posts as if they were the plague.

             

            Yes, this Adobe “Build an application in an hour” pitch is dazzling and a lot of fun, but from my view point, useless – unless I am missing something big time.

             

            Anybody want to respond?

             

            Carlos

            • 3. Re: I am in data-centric hell and want out
              David_F57 Level 5

              hi,

               

              I normally use amfphp which works differently to the DCD methods but you can use lastresult to feed into an arrayCollection, this is a simple use case if that helps at all.

               

               

              <?xml version="1.0" encoding="utf-8"?>

              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                 xmlns:s="library://ns.adobe.com/flex/spark"

                 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:clientservice="services.clientservice.*"

                   creationComplete="application1_creationCompleteHandler(event)">

              <fx:Script>

              <![CDATA[

              import mx.collections.ArrayCollection;

              import mx.controls.Alert;

              import mx.events.FlexEvent;

              import mx.rpc.events.ResultEvent;

               

              [Bindable] private var dataArr:ArrayCollection = new ArrayCollection()

               

              protected function application1_creationCompleteHandler(event:FlexEvent):void

              {

              getAllClientResult.token = clientService.getAllClient();

              }

               

              protected function getAllClientResult_resultHandler(event:ResultEvent):void

              {

              dataArr =  event.currentTarget.lastResult;

              }

               

               

              ]]>

              </fx:Script>

              <fx:Declarations>

              <s:CallResponder id="getAllClientResult" result="getAllClientResult_resultHandler(event)"/>

              <clientservice:ClientService id="clientService" fault="Alert.show(event.fault.faultString + '\n' +

              event.fault.faultDetail)" showBusyCursor="true"/>

              </fx:Declarations>

               

              <mx:DataGrid x="292" y="249" id="dataGrid" dataProvider="{dataArr}">

              <mx:columns>

              <mx:DataGridColumn headerText="id" dataField="id"/>

              <mx:DataGridColumn headerText="name" dataField="name"/>

              <mx:DataGridColumn headerText="surname" dataField="surname"/>

              </mx:columns>

              </mx:DataGrid>

              </s:Application>

              1 person found this helpful
              • 4. Re: I am in data-centric hell and want out
                cheftimo Level 2

                Hey David, thanks for the tips.

                 

                I tried before to create an ArrayCollection, but maybe I used something other than lastResult and the compiler did not like it.

                 

                I work with ColdFusion, but that should not make any difference, I will play with your suggestions. I suspect something along these lines will work. I will report on the results.

                 

                Thanks again,

                 

                Carlos

                • 5. Re: I am in data-centric hell and want out
                  cheftimo Level 2

                  Hi David, I have been playing with this for a while; when I try to set that lastResult to ArrayCollection, the compiler throws an error – implicit coercion of FlexEvent to RPC Event.

                   

                  Have you actually used the code you provided and it worked?

                   

                  Thanks,

                   

                  Carlos

                  • 6. Re: I am in data-centric hell and want out
                    David_F57 Level 5

                    hi,

                     

                    The code provided is a working example, Maybe its how the php returns the data as compared to cfm.

                     

                    If you check the last result in your debug view you will see what type of data is returned.

                     

                    this code is a bit old but pushing the data into an arraycollection maybe helpful to you.

                     

                     

                    private function qryClients(res:ResultEvent):void

                    {

                         var dp:Array=new Array();    

                         var i:Number=0;

                         while(i < res.result.length)

                         {

                              dp.push(res.result[i]);

                              i++;

                         }

                         clientsArray = new ArrayCollection(dp);

                    }

                    1 person found this helpful
                    • 7. Re: I am in data-centric hell and want out
                      David_F57 Level 5

                      hi,

                       

                      I was playing around with something on a different host and my 'normal' code broke, not sure what I did but the result was suddenly returned differently, anyway this allowed me to use the result in an arraycollection, thought it maybe another thing you could look at..

                       

                      private function qryClients(res:ResultEvent):void

                      {

                      var dte:Date = new Date();

                      lbl.text= String((dte.time-stime)/1000);

                      clientData = new ArrayCollection(res.result as Array);

                      }

                      David

                      • 8. Re: I am in data-centric hell and want out
                        cheftimo Level 2

                        Hey David,

                         

                        I have been playing with this DCD for days because I wanted to use it in an actual little project for one of my sites. I learned one thing: the lastResult can be different, depending on what component one is binding to. In the examples you provided, you were using a DataGrid, which ends up with an ArrayCollection as the dataProvider; I have been using a List, whose dataProvider is some ******* thing I could not figure out – for example, I was never able to make it show up in the debugger.

                         

                        I looked at Tour de Flex, which was updated just a few days ago. The RemoteObject examples I found there use plain old mx:RemoteObject to access data; I did not see any using a DCD-generated service. That makes me wonder why, if this DCD is so great, it is not being used in the latest showcase.

                         

                        I recreated the same little project, this time using s:RemoteObject to create a service that can be called from any component – that took me less than an hour; so far, it’s being called from 2 different components, each one calling one of the two methods the CFC defines so far. Everything works just as well, maybe faster than in the original project, and I am able to use the debugger to see what is going on.

                         

                        Now, instead of 5 huge value object AS files, I have two much smaller ones. The new debug SWF is 109 KB, the first one 138 KB – that’s 26% bigger.

                         

                        So, since I am not into masochism, I will be completing the project using my service. Right now, from my point of view, DCD is OK for prototyping/preliminary testing; it’s fun and very dazzling, but useless.

                         

                        Thank you for all the help; if you learn of any good stuff about DCD, please post again and let us know.

                         

                        Best regards,

                         

                        Carlos

                        • 9. Re: I am in data-centric hell and want out
                          cheftimo Level 2

                          Hello David:

                           

                          I don’t really know who you are or if you are associated with Adobe, but I think you know what you are doing with FB 4 and the new Spark components. Through this post, I am trying to reach you; it’s the only way I know how, since your email address for these forums is private (you can always communicate with me at http://www.facebook.com/timos, if you wish). I am assuming you will see this, since you are subscribed to this thread.

                           

                          If you have time, could you please look at this post, http://forums.adobe.com/thread/643462?tstart=0 and see if you have any ideas? It’s an issue that should be very common, but I am not getting any action.

                           

                          Best regards,

                           

                          Carlos