3 Replies Latest reply on Jan 16, 2009 10:31 AM by ntsiii

    Problem with selectedItem on datagrid

    cokeeffe
      I get the following error, in my browser (Firefox on Mac) when I select something from a datagrid which in turn shows data in text inputs, however, it shows data in the 'main' text inputs i have (everything with a form tag below), but i have a another datagrid (dgCourses and dgNotes) it should fill, but the data appears in the main text inputs but not in the dgCourses and dgNotes datagrid unless I click on the item a second time..


      quote:

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at Customers/getCustomerDetail()[/Users/colinokeeffe/Sites/flex/TestBed/src/Customers.mxml:4 6]
      at Customers/__goGetCustomerDetail_result()[/Users/colinokeeffe/Sites/flex/TestBed/src/Custo mers.mxml:64]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.rpc.http.mxml::HTTPService/ http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.2.0\framewor ks\projects\rpc\src\mx\rpc\http\mxml\HTTPService.as:290
      at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\ projects\rpc\src\mx\rpc\AbstractInvoker.as:193
      at mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responde r.as:43]
      at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\ AsyncRequest.as:74]
      at DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\s rc\mx\messaging\channels\DirectHTTPChannel.as:403]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at flash.net::URLLoader/onComplete()



      here is the MXML code


      quote:

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" initialize="goGetAllCustomers.send()" width="100%">
      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import mx.controls.Alert;

      public function getAllCustomers(event:ResultEvent):void
      {
      dgCustomers.dataProvider = event.result.person;
      }

      public function getCustomerDetail(event:ResultEvent):void
      {

      txtID.text = event.result.person.id;
      txtTitle.text = event.result.person.title;
      txtFirstName.text = event.result.person.first_name;
      txtLastName.text = event.result.person.last_name;
      txtPhone.text = event.result.person.phone;
      txtMobile.text = event.result.person.mobile;
      txtFax.text = event.result.person.fax;
      txtEmail.text = event.result.person.e_mail;
      txtAddress1.text = event.result.person.address_1;
      txtAddress2.text = event.result.person.address_2;
      txtAddress3.text = event.result.person.address_3;
      txtCity.text = event.result.person.city;
      txtCounty.text = event.result.person.county;
      colorPicker.selectedColor = event.result.person.tag;
      txtPps.text = event.result.person.pps;

      dgCourses.dataProvider = event.result.person.courses.course;
      dgNotes.dataProvider = event.result.person.notes.note;

      }

      public function handleFault(event:FaultEvent):void
      {
      Alert.show(event.fault.faultString, "Error");
      }
      ]]>
      </mx:Script>
      <mx:HTTPService result="getAllCustomers(event);" fault="handleFault(event);" id="goGetAllCustomers" resultFormat="e4x"
      url="customers.php" useProxy="false">
      <mx:request xmlns="">
      <id>id</id>
      </mx:request>
      </mx:HTTPService>

      <mx:HTTPService result="getCustomerDetail(event);" fault="handleFault(event);" id="goGetCustomerDetail" resultFormat="e4x"
      url="customers.php" useProxy="false">
      <mx:request xmlns="">
      <id>{dgCustomers.selectedItem.id}</id>
      </mx:request>
      </mx:HTTPService>

      <mx:DataGrid id="dgCustomers" x="10" y="10" width="456" click="goGetCustomerDetail.send()" height="542">
      <mx:columns>
      <mx:DataGridColumn headerText="ID" dataField="id" visible="false"/>
      <mx:DataGridColumn headerText="Name" dataField="name" width="110"/>
      <mx:DataGridColumn headerText="Address 3" dataField="address_3"/>
      <mx:DataGridColumn headerText="City" dataField="city"/>
      <mx:DataGridColumn headerText="Phone" dataField="phone"/>
      <mx:DataGridColumn headerText="Mobile" dataField="mobile"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:VRule x="474" y="10" height="542"/>
      <mx:Panel x="484" y="10" width="539" height="542" layout="absolute" title="Student Details">
      <mx:Form x="0" y="0" width="257" height="252">
      <mx:FormItem label="ID">
      <mx:TextInput id="txtID" maxChars="5" width="51"/>
      </mx:FormItem>
      <mx:FormItem label="Title">
      <mx:TextInput width="143" id="txtTitle"/>
      </mx:FormItem>
      <mx:FormItem label="First Name">
      <mx:TextInput width="145" id="txtFirstName"/>
      </mx:FormItem>
      <mx:FormItem label="Last Name">
      <mx:TextInput id="txtLastName" width="146"/>
      </mx:FormItem>
      <mx:FormItem label="Phone">
      <mx:TextInput id="txtPhone" width="146"/>
      </mx:FormItem>
      <mx:FormItem label="Mobile">
      <mx:TextInput id="txtMobile" width="146"/>
      </mx:FormItem>
      <mx:FormItem label="Fax">
      <mx:TextInput id="txtFax" width="146"/>
      </mx:FormItem>
      <mx:FormItem label="E-Mail">
      <mx:TextInput id="txtEmail" width="146"/>
      </mx:FormItem>
      </mx:Form>
      <mx:Form x="255" y="0" width="264" height="252">
      <mx:FormItem label="Address 1">
      <mx:TextInput id="txtAddress1" width="150"/>
      </mx:FormItem>
      <mx:FormItem label="Address 2">
      <mx:TextInput id="txtAddress2" width="150"/>
      </mx:FormItem>
      <mx:FormItem label="Address 3" width="224">
      <mx:TextInput id="txtAddress3"/>
      </mx:FormItem>
      <mx:FormItem label="City">
      <mx:TextInput width="150" id="txtCity"/>
      </mx:FormItem>
      <mx:FormItem label="County">
      <mx:TextInput width="151" id="txtCounty"/>
      </mx:FormItem>
      <mx:FormItem label="Tag">
      <mx:ColorPicker id="colorPicker"/>
      </mx:FormItem>
      <mx:FormItem label="PPS">
      <mx:TextInput width="148" id="txtPps"/>
      </mx:FormItem>
      </mx:Form>
      <mx:TabNavigator x="10" y="260" width="499" height="232">
      <mx:Canvas label="Notes" width="100%" height="100%">
      <mx:DataGrid x="10" y="10" width="477" height="109" id="dgNotes" click="txtNotes.text=dgNotes.selectedItem.text">
      <mx:columns>
      <mx:DataGridColumn headerText="Date" dataField="date" width="80"/>
      <mx:DataGridColumn headerText="Time" dataField="time" width="60"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:TextArea x="10" y="118" width="477" height="71" id="txtNotes"/>
      </mx:Canvas>
      <mx:Canvas label="Courses" width="100%" height="100%">
      <mx:DataGrid x="10" y="10" width="477" height="179" id="dgCourses">
      <mx:columns>
      <mx:DataGridColumn headerText="Code" dataField="code" width="100"/>
      <mx:DataGridColumn headerText="Course" dataField="title"/>
      <mx:DataGridColumn headerText="Start Date" dataField="start_date" width="80"/>
      <mx:DataGridColumn headerText="Time" dataField="time"/>
      <mx:DataGridColumn headerText="Tutor" dataField="tutor"/>
      <mx:DataGridColumn headerText="Location" dataField="name"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:Canvas>
      </mx:TabNavigator>
      </mx:Panel>

      </mx:Application>


      h
      help?!
        • 1. Re: Problem with selectedItem on datagrid
          Level 7

          "cokeeffe" <webforumsuser@macromedia.com> wrote in message
          news:gkp17e$88r$1@forums.macromedia.com...
          >I get the following error, in my browser (Firefox on Mac) when I select
          > something from a datagrid which in turn shows data in text inputs
          >
          >
          >
          quote:

          TypeError: Error #1009: Cannot access a property or method of a null
          > object
          > reference.
          > at
          > Customers/getCustomerDetail()[/Users/colinokeeffe/Sites/flex/TestBed/src/Custome
          > rs.mxml:46]
          > at
          > Customers/__goGetCustomerDetail_result()[/Users/colinokeeffe/Sites/flex/TestBed/
          > src/Customers.mxml:64]

          I'd put a break point on lines 46 and 64 and look in the variables window to
          see what's null that you're expecting to contain a value.

          HTH;

          Amy


          • 2. Re: Problem with selectedItem on datagrid
            cokeeffe Level 1
            Solved it..

            the problem was the tab's were not being created when the page loads and so when I select something from the datagrid, the tab's did not exist to place the data into... in a nutshell, i had to use the creationPolicy="all" in <mx:TabNavigator x="10" y="260" width="499" height="232"> and it worked..
            • 3. Re: Problem with selectedItem on datagrid
              ntsiii Level 3
              Be aware that setting creationPolicy="all" can have serious performance consequences. Especially if it becomes a habit.

              Setting component's properties from the "outside" is not a best practice anyway. Have your components bind to a model, or use your own event framework to populate the child components.