10 Replies Latest reply on Nov 15, 2006 3:21 PM by Josh Johnson

    Refreshing a Component Display

    Josh Johnson Level 1
      Apologies for the length of the post, but I'm guessing it would be useful to set the stage a little for this...

      I have an application that references two components in a master/detail layout where one component is the master and the other is the detail. Within the master component, I have a combo box that specifies the "view" of the data. I expose the selected "view" in the component via a public var:String.

      The detail component also has a "view" variable, and within the main application mxml (where the components are referenced), I specify that the detail components value for "view" equals the master's "view" value. All is well so far.

      Now within the detail component I have a viewStack of containers which correspond to the number of possible views in the master's combo box, and viewStack.selectedChild = this[view].

      So in the end, if I change the value of the combo box in the master pane, the viewStack in the detail pane changes accordingly... except for one problem. The detail component isn't updating immediately when the combo box changes values, but only updates with other data being supplied to the detail component is updated. What's really odd is that if I display the "view" string as a label within the detail component, then it does update as expected! But for some reason when the variable is only driving the viewStack display, any changes to the "view" variable are ignored with respect to the detail component being refreshed.

      Any ideas on why the variable changes are being ignored and how to remedy this situation?

      Thanks,
      Josh
        • 1. Re: Refreshing a Component Display
          peterent Level 2
          Are the data in the detail component dynamically bound to something? The part that confuses me is, "The detail component isn't updating immediately when the combo box changes values, but only updates with other data being supplied to the detail component is updated."

          When you change the ComboBox in the master, does the ViewStack in the detail change?

          Are the components within that ViewStack children the ones that are not being changed?

          For example, if you are seeing the first ViewStack child and change the master ComboBox such that the second ViewStack child appears, the components on that second child do not reflect the correct data until some other data update happens?
          • 2. Re: Refreshing a Component Display
            Josh Johnson Level 1
            So the master component also includes a dataGrid of items, where the selected item has additional details shown in the detail component when selected.

            So when I change the combo box in the master component, the viewStack doesn't change in the detail component, but if I select a different item in the master dataGrid, the viewStack in the detail component DOES update to the correct stack item as well as updating the bound data.

            So all the data seems to be getting updated (based on the selected item in the master dataGrid), but the viewStack children aren't switching when just the combo box in the master component is changed.

            Does that make it a little clearer?
            • 3. Re: Refreshing a Component Display
              ntsiii Level 3
              Could this be the deferred instantiation issue? Does it work if you first navigate to the all the views?

              For testing purposes ONLY (or Gordon will have my head) set the ViewStack creationPolicy="all", and try it again.

              Tracy
              • 4. Re: Refreshing a Component Display
                Josh Johnson Level 1
                Nope, this doesn't seem to be related to the instantiation of the ViewStack children. I tried the creationPolicy="all" example, but it didn't have any effect.

                The only thing that seems to make it work as expected is to display the "view" string in a label element in the detail. What I find odd is that I'm pushing data into this detail component using 2 variables. One is a string and the other is an object. Changing the data in the bound object makes it update, but changing data bound to the string is ignored.
                • 5. Re: Refreshing a Component Display
                  ntsiii Level 3
                  How are you setting the view variable in the component?

                  And have you marked it as [Bindable], if you are binding to it?

                  For that matter, where and how are you invoking: "viewStack.selectedChild = this[view]. "?

                  Tracy
                  • 6. Re: Refreshing a Component Display
                    Josh Johnson Level 1
                    The script section on my detail component look like this...

                    [Bindable]
                    public var dataProvider:Object;
                    [Bindable]
                    public var view:String;

                    private function setView():void {
                    if (dataProvider != null) {
                    if (view != null) {
                    theViewStack.selectedChild=this[view];
                    }else{
                    theViewStack.selectedChild=this['error'];
                    }
                    }else{
                    theViewStack.selectedChild=this['null'];
                    }
                    }

                    and on the 'creationComplete' and 'updateComplete' events on the component I'm calling the setView() function.
                    • 7. Re: Refreshing a Component Display
                      Josh Johnson Level 1
                      For additional info, the component is based on a Panel, where the title of the panel is defined as:
                      title="{dataProvider.name}"

                      What's funny is that if I change the title definition to:
                      title="{dataProvider.name + ': ' + view}"
                      everything starts behaving correctly. (i.e. when I change the view in the master combo box, the detail component updates accordingly.)
                      • 8. Re: Refreshing a Component Display
                        ntsiii Level 3
                        Have you verified that "view" has a value when those two events fire?
                        • 9. Re: Refreshing a Component Display
                          Josh Johnson Level 1
                          Yep. As I said, if I write the view string into the title of the panel, it displays and makes the ViewStack update correctly.
                          • 10. Re: Refreshing a Component Display
                            Josh Johnson Level 1
                            Just a bump to see if anyone else had any ideas on this. Could the fact that one variable is a string and the other is an object be affecting this?