1 Reply Latest reply on Jun 28, 2011 6:31 AM by UbuntuPenguin

    Data Binding Issue

    rabinprithvi Level 2

      To learn more about data binding i just commented the bindable metadata tag in Employee VO class .

      Data Binding is working in case 1 and not in case 2.

      Any suggestion is appreciated.

       

      Case 1 : Works Fine

       

      EmployeeVO Class

       

       

      /*[Bindable]*/            

      public class EmployeeVO

      {

           public var employeeName:String;

       

       

           public function EmployeeVO(name:String)

           {

                this.employeeName = name;

           }

       

       

       

      }

       

       

       

      EmployeeView MXML

       

       

      [Bindable]

      private var employeeVO:EmployeeVO = new EmployeeVO("John");

       

      private function changeEmployee():void

      {

           employeeVO = new EmployeeVO("Jack");

       

      }

       

       

       

      <s:TextInput id="t1" text="{employeeVO.employeeName}" editable="false"/>

      <s:Button label="Change Employee" click="changeEmployee()"/>

       

      ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ -----------------------------

       

      Case 2 : Not Working

       

      EmployeeVO Class

       

      /*[Bindable]*/

       

      public class EmployeeVO

      {

       

       

           public var employeeName:String = "John";

       

           public function EmployeeVO()

           {

                //empty constructor

       

           }    

       

       

      }

       

      EmployeeView MXML

       

      [Bindable]

      private var employeeVO:EmployeeVO = new EmployeeVO();

       

       

       

       

      private function changeEmployee():void

      {

           employeeVO = new EmployeeVO();

           employeeVO.employeeName = "Jack"

      }

       

      <s:TextInput id="t1" text="{employeeVO.employeeName}" editable="false"/>

      <s:Button label="Change Employee" click="changeEmployee()"/>

       

      ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ -----------------------------

       

      I debuged the application  and came to a conclusion that data binding will occur for the first time even when bindable metadata tag is absent.

      But not thereafter.

       

      Can someone please throw more light on this.

       

       

       

       

        • 1. Re: Data Binding Issue
          UbuntuPenguin Level 4

          The property "employeeName" isn't bindable so when you change it from null to something else, the view isn't going to refresh.  In case one, I assume what is happening is that the name of the employee is getting set, then the bindings attached to text field update the view to the property on your object.

           

          To clarify for yourself, in example one pass "Jack" to the employee constructor, then set the employee name to "Michael" and look at what the view shows.