0 Replies Latest reply on Oct 29, 2010 8:42 AM by livletdie77

    Problem in Saving Data Fields to an Object

    livletdie77

      Hi,

       

      I have a form which includes the User Information when you insert the user Id on to a field. When you enter the user Id in the field and submit the results get inserted into a  UserInfoBean class in java. The UserInfoBean object is retrieved to the getUserDat() in flex. The first time I do this it assignes the data to the  "userInfo" and I include this into the fields as

                                 <s:TextInput id="firstNameId" text="{userInfo.FirstName}"/>

                                 .....

      The issue I am having is IF I do move to another section and comeback and try to look for another user the "userInfo" becomes NULL but the results.getItemAt(0) has data object UserInfoBean. When I try to print inside the getUserData() the userInfo.FirstName I get Null since the userInfo is NULL and results.getItemAt(0).FirstName I get the values.

       

      The code is attached below.

       

      Is there a way to fix this issue? How should I get the result into the userInfo?

       

      Thank you,

      Hass

       

       

      CODE:

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

      MXML Code

      <<UserInfo.mxml>>


      <fx:Script source="UserScript.as"/>

      <fx:Declarations>

      <services:DepositInfo id="userData" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
      <s:CallResponder id="getUserDataResult" result="getUserData (event)"/>
      </fx:Declarations>  


      <s:Label text="User Id:" id="userIdLb"/>  <s:TextInput id="userId" text=""/>
      <s:Button label="Show" id="showBtn" click="
      loadUser()"/>
      ......

      ......

      <s:TextInput id="firstNameId" text="{userInfo.FirstName}"/>

      <s:TextInput id="lastNameId" text="{userInfo.LastName}"/>

      <s:TextInput id="emailId" text="{userInfo.Email}"/>


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

      ActionScript Code


      <<<UserScript.as>>>


      [Bindable] public  var userInfo:UserInfoBean = new UserInfoBean();


      private function loadUser(){

      getUserDataResult.token = userData.getUserInfoData(userId.text.toString());

      }


      private function getUserData (event:ResultEvent):void{
          var results :ArrayCollection;
          results=event.result as ArrayCollection;
        
          if(results.length != 0){
              userInfo=results.getItemAt(0) as UserInfoBean;
          }
      }