4 Replies Latest reply on Feb 24, 2010 9:12 AM by carstephun

    refresh comboboxes with the same source after remote call

    carstephun Level 1

      Hi,

       

      I have main page with a combobox bound to a remote source. I have a dialog window (TitleWindow) that has a combobox bound to the same remote call based source. After committing /in the TitleWindow/ my changes back to the server and call to remote to refresh the data only the combobox in the TitleWindow refreshes it's data, the slightly hidden combobox on the main page remains the same, no data change happen.

       

      What should I do that the bindable property that acts as source for both comboboxes affects on both after remote call return with the result?

       

      Environment is FB4 / B2 SDK 3.4

       

       

      <!-- Main page -->
      <d:dataVFManager id="dVFForm" />
      <mx:ComboBox
           id="cbLLL"
           dataProvider="{dVFForm._VFManufacturers}"
           labelField="desc"
           prompt="Select Manufacturer" />
      
      <!-- TitleWindow -->
      
      <d:dataVFManager id="dVFManufacturer" />
      
      <mx:ComboBox id="cbVFMs" 
           dataProvider="{dVFManufacturer._VFManufacturers}"
           labelField="desc"
           prompt="Select Manufacturer"
           change="cbVFMs_changeHandler(event)"/>
      
           <!-- commit changes -->
      
           protected function button1_clickHandler(event:MouseEvent):void
      {
           //... preparing _model for data entry -> code removed
           dVFManufacturer.roVFManager.saveVFManufacturerEntry( _model );
      }
      
      
      <!-- DataSource / DataManager -->
      
      <?xml version="1.0" encoding="utf-8"?>
      <mx:UIComponent xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="dataVF_creationCompleteHandler(event)">
           <mx:Metadata>
                [Event(name="LoadVFEntryFinished")]
                [Event(name="LoadVFManufacturerEntryFinished")]
           </mx:Metadata>
           <mx:Script>
                <![CDATA[
                     import data.valueObjects.VOVehicleFeature;
                     
                     import mx.collections.ArrayCollection;
                     import mx.controls.Alert;
                     import mx.events.FlexEvent;
                     import mx.rpc.events.ResultEvent;
                     
                     [Bindable]
                     public var _VFManufacturers:ArrayCollection;
                     <!-- ... properties class variables removed -->
                     
                     private function doGetVFManufacturers( event:ResultEvent ):void
                     {
                          _VFManufacturers = new ArrayCollection( event.result as Array);
                     }
                               <!-- ... codes removed -->
                     public function initData():void
                     {
                          roVFManager.getOperation("getVFManufacturers").send();
                     }
      
                     protected function dataVF_creationCompleteHandler(event:FlexEvent):void
                     {
                          roVFManager.getVFManufacturers();
                     }
                ]]>
           </mx:Script>
           <mx:RemoteObject id="roVFManager" destination="zend" source="VFManager" showBusyCursor="true" fault="Alert.show(event.fault.faultString,'Error')">
                <mx:method name="getVFManufacturers" result="doGetVFManufacturers(event)"/>
                     <!-- codes removed -->
                <mx:method name="saveVFManufacturerEntry" result="doSaveVFManufacturerEntry(event)" />
           </mx:RemoteObject>
      </mx:UIComponent>
      
      
      
      
      
      

       

       

       

      I simplified the example a bit.

       

      r. Sandor

        • 1. Re: refresh comboboxes with the same source after remote call
          Gregory Lafrance Level 6

          You're probably better off using a model to represent the data that both ComboBoxes get their data from, and then dispatch a custom event when that data must change, either from the main app or from the titlewindow. That way both ComboBoxes will refresh after that one data source changes.

           

          Here are my Adobe Flex Cookbook posts on a simple MVC architecture and custom events that should answer this for you.

           

          http://cookbooks.adobe.com/post_Very_simple_example_of_using_custom_events_to_pass-15466.h tml

          http://cookbooks.adobe.com/post_Building_a_wizard_using_a_simplified_MVC_architect-11246.h tml

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          1 person found this helpful
          • 2. Re: refresh comboboxes with the same source after remote call
            carstephun Level 1

            Hi Greg,

             

            I'm familiar with both custom event and MVC architecture / not kinda' Flex based/ but as I remember from the livedocs whenever the content of the arraycollection changes a COLLECTION_CHANGE event occurs that will force each bounded component in this case ComboBox to change according to the changes in the arraycollection. I simply don't see the point to overhaul the complete application into MVC if it doesn't need to.

             

            The main reason I've choosen flex is that this sort of things happens automatically and I don't have to delve deep into the structure of the components and manually do event handling and this things.

             

            I assume some sort of event propagating problems occurs here, but I can't figure out where and how.

             

            r. Sandor

             

            Additionally

             

            I figured out whenever a popup window is created the event propagation from the custom datamanager component wouldn't be dispatched for the main window, only for the titlewindow.

             

            Changes2

             

            I got the solution. It was because I used every time a new instance of the datamanager instead of a global scoped binding. It's time for a singleton or Registry pattern.

            • 3. Re: refresh comboboxes with the same source after remote call
              Gregory Lafrance Level 6

              But your code suggests you have two different dataProviders:

               

              dVFForm._VFManufacturers

              dVFManufacturer._VFManufacturers

               

              Are they both updated when the remote data updates?

               

              What are they, collection objects like ArrayCollection and XMLListCollection?

              1 person found this helpful
              • 4. Re: refresh comboboxes with the same source after remote call
                carstephun Level 1

                Hi Greg,

                 

                My suggestion was simply wrong, they work on the same kind / group of data so I put them into one remote object, but I forgot that each mxml component entry is an object instantiation.

                yes, indeed they have been ArrayCollections, but meanwhile I had a better idea and did the following in the datamanager component.

                 

                <mx:ArrayCollection id="_VFManufacturers" source="{ArrayUtil.toArray(roVFManager.getVFManufacturers.lastResult)}"/>
                

                 

                I simply bound to the last result of the remote object.

                 

                I approtiate your force to help me, but sometimes I had to dig my head into sand to solve my own conceptions :-)

                 

                r. Sandor