9 Replies Latest reply on Aug 5, 2011 2:44 PM by kzakarias

    Datagroup databind not working

    kzakarias

      Hi, all.

       

      I have a datagroup which is databinded to a collection.

       

      <s:DataGroup id="tasksContainer" width="100%"
                                           dataProvider="{tasksCollection}"
                                           itemRenderer="components.taskRender"
                                           >
                                  <s:layout>
                                      <s:VerticalLayout gap="0" verticalAlign="middle" />
                                  </s:layout>
                                         
          </s:DataGroup>

       

       

      I have a resultHandler that receives and updates the tasksCollection when a new entry has been made.

       

      protected function getAllTasksResult_resultHandler(event:ResultEvent):void
                  {
                      tasksCollection = getAllTasksResult.lastResult;
                  }

       

      Other parts of my application has no problem binding to the tasksCollection but for some reason the datagroup does not update.

       

      I have tried putting in an arrayCollection.refresh() which doesn't work either?

       

      Any suggestions?

        • 1. Re: Datagroup databind not working
          kokorito Level 4

          you've made the variable bindable?

           

          [Bindable] protected var tasksCollection:ArrayCollection;

           

           

          in a handler you use the result of the service

           

          tasksCollection = getAllTasksResult.result as ArrayCollection;

          • 2. Re: Datagroup databind not working
            kzakarias Level 1

            Hi,

             

            Sorry, my question might have been a little short.


            I have a responder function when the data comes back from the server:

            protected function getAllTasksResult_resultHandler(event:ResultEvent):void
                        {
                            tasksCollection = getAllTasksResult.lastResult as ArrayCollection;
                          
                        }

             

             

            this data is sent to a bindable arraycollection:

            [Bindable]
                        public var tasksCollection:ArrayCollection = new ArrayCollection;


             

             

            the datagroup listens for the changes:


            <s:DataGroup id="tasksContainer03" width="100%"
                                                 dataProvider="{tasksCollection}"
                                                 itemRenderer="components.taskRender"
                                                 >
                                        <s:layout>
                                            <s:VerticalLayout gap="0" verticalAlign="middle" />
                                        </s:layout>
                                               
                                    </s:DataGroup>

             

             

            However, the datagroup does not update while other components binded in the same manner to the tasksCollection do. Ilist and datagrids update correctly.

            • 3. Re: Datagroup databind not working
              Amy Blankenship Level 4

              Is your TasksRenderer showing Images?  I find that when I have Images in an ItemRenderer, I often have to manually call executeBindings when the image changes.

              • 4. Re: Datagroup databind not working
                NickDF__

                Do you use the same service method (getAllTasksResult) with your other componets that work as you expect them to do?

                 

                And also, did you try debugging it to see if the tasksCollection gets the expected values from the service in your result handler?

                • 5. Re: Datagroup databind not working
                  saisri2k2 Level 4

                  also try datagroup.invalidateDisplayList();

                  • 6. Re: Datagroup databind not working
                    kzakarias Level 1

                    Hi all,

                     

                    Thank you all for your advice. I have made a few tests and found where the problem is.


                    I tried using the simplest of ItemRenderers to see if the data is received correctly and it is. If I use the following setup everything works just fine.

                     

                    <s:DataGroup id="tasksContainer03" width="100%"
                                                         dataProvider="{tasksCollection}" >
                                                        <!-- itemRenderer="components.taskRender"-->
                                                        
                                                <s:layout>
                                                    <s:VerticalLayout gap="0" verticalAlign="middle" />
                                                </s:layout>

                    --new code with basic itemrenderer--
                                            <s:itemRenderer>
                                                <fx:Component>
                                                    <s:ItemRenderer>
                                                        <s:Label text="{data.taskname}"/>
                                                    </s:ItemRenderer>
                                                </fx:Component>
                                            </s:itemRenderer>

                                                       
                                            </s:DataGroup>

                     

                    So it seems my custom Itemrenderer is causing the problems.

                    My renderer looks like this:

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                    xmlns:s="library://ns.adobe.com/flex/spark"
                                    xmlns:mx="library://ns.adobe.com/flex/mx" width="100%"
                                    xmlns:components="components.*" creationComplete="init();" >
                        <fx:Script>
                            <![CDATA[
                                import components.*;
                               
                                import mx.utils.ObjectProxy;
                               
                                [Bindable]
                                public var dataProxy:ObjectProxy;
                             
                                private function init():void
                                {
                                    dataProxy = new ObjectProxy(data);
                                }

                            ]]>
                        </fx:Script>



                        <s:layout>
                            <s:VerticalLayout verticalAlign="middle"/>
                        </s:layout>


                        <components:taskComponent id="taskname" text="{dataProxy.taskname}" task="{data}" width="100%"  />
                       
                    </s:ItemRenderer>

                     

                     

                    The custom renderer basically just uses a custom component to show the data.

                    Has anyone had any problems with using custom components within custom item renderers???

                    • 7. Re: Datagroup databind not working
                      Amy Blankenship Level 4

                      You're creating an ObjectProxy from your data when the component is first created, but you're not providing a path to change the contents of the ObjectProxy when the data changes.  I would suggest getting rid of the ObjectProxy altogether and just binding to the data, but if you can't, try something like this:

                       

                      override public function set data(value:Object):void {

                           if (value != data) {

                                super.data = value;

                                dataProxy = new ObjectProxy(value);

                           }

                      }

                      • 8. Re: Datagroup databind not working
                        kzakarias Level 1

                        Hi again,

                         

                        Resolved the issue.

                        The taskComponent receives two variables. text={dataProxy.taskname} and task={data}.

                         

                        If I use the text varialbe to get the taskname displayed the list datagroup does not get updated.

                        However if I use the {data.taskname} instead it does.

                        So, as I see it, the bindability is meesed up when I convert the {data} to dataProxy on the init function.

                         

                        Any comments that can explain this will we appreciated.

                         

                        Br,

                        Karsten!

                        • 9. Re: Datagroup databind not working
                          kzakarias Level 1

                          Thanks Amy!