7 Replies Latest reply on Jun 8, 2009 3:23 AM by robegv

    A simple newbie question - retrieving data to edit and return

    robegv

      Hi

       

      I hope someone can help me (bit new to flex as you will be able to tell!)

       

      i have a simple form which allows me to enter details about a client(person) and save this to the database via coldfusion cfc so far so good.

       

      Howver a want to retriev that record record back later on a make changes.  difficulty i am having is not the retrieval of therecord itself, as the record can be returned to a datgrid with no probs, but binding the arraycollection to the relevant fields.

       

      my code so far is as follows trhe field i am looking for here is retrieved as a "Surname" and i want it top popluate the textinput field...

      (and i thought my learning was going so well  !)

       

      [Bindable]
         public var getepisode:ArrayCollection= new ArrayCollection ();

       

      //this is the bit that needs help methinks

       

      public function returnHandler(event:ResultEvent):void {
          Surname.text as Surname.string
          
         }

       


            public function errorHandler(event:FaultEvent):void {
          Alert.show(event.fault.message);   
         }
        

        
        
         ]]>
          </mx:Script>



      <!-- insert rpc to get client data-->
      <mx:RemoteObject id="ClientQuery"
         destination="ColdFusion"
         source="buildtest.getepisode"
         showBusyCursor="true"
         fault="errorHandler(event)">
                <mx:method name="getepisode" result="returnHandler(event)"/>
      </mx:RemoteObject>

       

      <mx:Form>
          
        <mx:FormItem direction="horizontal" label="surname (roberts)" required="true" visible="true" width="100%" horizontalAlign="left">
           <mx:TextInput enabled="true" id="Surname" text="{returnHandler.Surname}"  width="100%" visible="true"/>
        </mx:FormItem>
           
      </mx:Form>

         

       

      grateful for any pointers

       

      cheers

        • 1. Re: A simple newbie question - retrieving data to edit and return
          Michael Borbor Level 4

          Hi there, if your function returns only one set of data if should be

          something like this

           

          public function returnHandler(event:ResultEvent):void {

              Surname.text =event.result.Surname;

           

             }

          • 2. Re: A simple newbie question - retrieving data to edit and return
            robegv Level 1

            Hi Michael

             

            thanks for your reply unfortunatley I am still not getting the field populated with the surname only a coded function (of "getclient42.Form44.FormItem57.Surname" )

             

            my code now looks like:

             

            [Bindable]
               public var getepisode:ArrayCollection = new ArrayCollection ();

               public function returnHandler(event:ResultEvent):void {
                  Surname.text = event.result.Surname;
               }
             
               public function errorHandler(event:FaultEvent):void {
                Alert.show(event.fault.message);   
               }
              
                ]]>
                </mx:Script>



            <!-- insert rpc to get client data-->
            <mx:RemoteObject id="ClientQuery"
                         destination="ColdFusion"
                         source="buildtest.getepisode"
                         showBusyCursor="true"
                         fault="errorHandler(event)">
                                     <mx:method name="getepisode" result="returnHandler(event)"/>
            </mx:RemoteObject>

             

            <mx:Form>

                <mx:FormItem direction="horizontal" label="Surname" required="true" visible="true" width="100%" horizontalAlign="left">
                           <mx:TextInput enabled="true" id="Surname" text="{Surname}" width="100%" visible="true"/>
              </mx:FormItem>

            </mx:Form>

             

            still if i drop a datagrid in and set my dataprovider to be the getepisode array the grid returns my required data .

             

            I think i am getting closer, but not sure if i am setting the binding correct in the textinput field i thought i could just use the id and the value would be set and leave out the 'text=' statement.

             

            if i can crack this i think i get going for quiet a while before hittiing the next stumbling block  - any help as always much appreciated.

             

            cheers

            • 3. Re: A simple newbie question - retrieving data to edit and return
              Michael Borbor Level 4

              Change your result handler to this

               

              public function returnHandler(event:ResultEvent):void {

                 Alert.show(event.result.toString());

               

                 }

               

              and post here what you see in the the Alert window that will pop up when the data returns

              • 4. Re: A simple newbie question - retrieving data to edit and return
                robegv Level 1

                hi

                 

                unfortunately there is nothing that gets returned in the alert it is just blank which is odd??

                 

                i guess that means nothing is being returned, but thats true how come i can put in a datagrid control with the same query and get results???

                • 5. Re: A simple newbie question - retrieving data to edit and return
                  Michael Borbor Level 4

                  You mentioned a DataGrid but in your code I can't see a DataGrid. Could you post that bit of code as well?

                  • 6. Re: A simple newbie question - retrieving data to edit and return
                    robegv Level 1

                    Hi

                     

                    Thanks fro your reply.

                     

                    With regard to the datagrid, I was using that to check that something was being returned in the ArrrayCollection. The code below show the array in the datagrid fine , no probs, i have left in ,but commented out, the alert part.

                     

                    The "clientref" field is passed into the code from a calling window and the grid shows the expected results, it just doesn't seem toget to the textinput field, v. odd..

                     

                    Thanks for any help - i am losing hair rapidly

                     

                    Full code.......

                     

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()" creationPolicy="all"
                    showCloseButton="true" xmlns:ns1="*" width="902" height="516"
                    close="PopUpManager.removePopUp(this);" horizontalAlign="left" title="get client record">

                      <mx:Script>
                            <![CDATA[      
                                import mx.managers.PopUpManager;
                                import mx.controls.TextArea;
                               import mx.managers.PopUpManager;
                                import mx.controls.Text;
                                import mx.printing.*;
                               import mx.events.ValidationResultEvent;
                                import mx.rpc.Fault;
                                import mx.rpc.events.FaultEvent;
                                 import mx.rpc.events.ResultEvent;
                                import mx.collections.ArrayCollection;
                                import mx.controls.Alert;
                                import mx.controls.CheckBox;
                                import mx.controls.TextInput;
                                import mx.controls.TextArea;
                                import mx.events.*;
                                import mx.collections.*;
                                import mx.controls.DataGrid;
                               
                                public function initApp():void {
                        ClientQuery.getepisode();
                       
                       }
                        // This function is called from main screen to put data into a text field
                       public function passData(passedData:String):void {
                        ClientRef.text = passedData
                       }
                                    private function handleCreationComplete():void {
                                    // Center the TitleWindow container over the control that created it.
                                    PopUpManager.centerPopUp(this);
                                   this.setStyle("borderAlpha", 1);
                                  }

                     

                      [Bindable]
                       public var getepisode:ArrayCollection = new ArrayCollection ();

                       public function returnHandler(event:ResultEvent):void {
                         clientDatagrid.dataProvider = event.result;
                         // Alert.show(event.result.tostring());
                       }
                     
                       public function errorHandler(event:FaultEvent):void {
                        Alert.show(event.fault.message);   
                       }
                      

                      
                      
                       ]]>
                        </mx:Script>



                    <!-- insert rpc to get client data-->
                    <mx:RemoteObject id="ClientQuery"
                       destination="ColdFusion"
                       source="buildtest.getepisode"
                       showBusyCursor="true"
                       fault="errorHandler(event)">
                              <mx:method name="getepisode" result="returnHandler(event)"/>
                    </mx:RemoteObject>

                     

                    <mx:Form>
                       <mx:FormItem direction="horizontal" label="ClientRef" required="true"  visible="true" width="100%" horizontalAlign="left">
                              <mx:TextInput text="clientref" id="ClientRef" editable="false" visible="true" width="100%"/>
                       </mx:FormItem>
                        
                      <mx:FormItem direction="horizontal" label="Surname" required="true" visible="true" width="100%" horizontalAlign="left">
                         <mx:TextInput enabled="true" id="Surname"  width="100%" visible="true"/>
                      </mx:FormItem>
                     
                      <mx:FormItem direction="horizontal" label="Forename" required="true" visible="true" width="100%" horizontalAlign="left">
                         <mx:TextInput enabled="true" id="Forename" text="" width="100%" visible="true"/>
                      </mx:FormItem>    
                    </mx:Form>

                    <mx:DataGrid id="clientDatagrid"/>

                     

                    </mx:TitleWindow>

                    • 7. Re: A simple newbie question - retrieving data to edit and return
                      robegv Level 1

                      Hi Michael,

                       

                      Any chance you can have a look at the code i posted last week - this should be a minute fix but I can't see it for looking !!

                       

                       

                       

                      cheers