8 Replies Latest reply on Oct 29, 2008 4:39 AM by Imagine8

    Passing data to components

    Imagine8

      I am only new to flex and using coldfusion and remote objects.
      I have been unable to find any good information on flex and coldfusion when trying to use components.
      If anyone can point me in the right direction?
      I am trying to pass data from one component to another in the main application file.
      I have a data grid in one component that when the user selects a record it sends the primary key back to the main app file.
      I then want to be able to pass that primary key in to another component or 2 that then goes and looks up related information.
      The code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="horizontal" xmlns:comps="comps.*">
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      import events.CustomClientClass;
      [Bindable]
      public var clientID:String;
      public function customeEvNameHandler(event:CustomClientClass):void
      {
      clientID = event.customClientID;
      Alert.show(clientID);
      }
      ]]>
      </mx:Script>
      <comps:clients id="clientView" clientIDEvt="customeEvNameHandler(event)"/>
      <comps:jobs id="jobsView" showClient="{clientID}"/>
      </mx:Application>

      Every time I have tried to pass the data in, it passes the string client ID not the numeric value.
      The alert in the main app file is showing the correct value
      The files work fine If i substitute the variable with a value.
      Just unclear how if I can pass the value to the the next component.


      Many thanks
      Jamie
        • 1. Re: Passing data to components
          atta707 Level 2
          Let's see if understand the problem; first of all we're talking about comps:jobs component and the problem is clientID is being passed to it as a String instead of a Number?

          If that's right, then what's the type of property showClient on jobs component? In you application, at least, it's typed as String.

          Did I understood your question?

          ATTA
          • 2. Re: Passing data to components
            Imagine8 Level 1
            Hi ATTA
            Thanks for the reply.
            I have 2 components one is clients view, which is a data grid being populated by remote object call to get all clients.
            When a user clicks on a client in the grid it passed the primary key ie clientID up to the main application level which I know is working and correct with the alert I have showing the correct ID.

            What I cant work out is how to pass that id to the jobs component in the main application file so the jobs component can do its own remote object call to get other data filtered on the client ID.
            I am not sure I am even on the right track in how to pass that data in, I am trying to populate clientID = event.customClientID;
            which works via the alert but if i pass it to the <comps:jobs id="jobsView" showClient="{clientID}"/> it is passing the literal string client ID and not the value of client ID, if that makes sense.
            I had it originally data type as an integer but if chasing the prob I tried String.

            Regards
            Jamie
            • 3. Re: Passing data to components
              atta707 Level 2
              is showClient property Bindable in the jobs module?

              Is it just public variable or do you have get and set function for it?

              Can you post some working code of this component?

              • 4. Re: Passing data to components
                Imagine8 Level 1
                I really appreciate your help.
                due to the nature of the client details I wont post working code at this stage.
                below is the jobs component code the coldfusion function is looking for an integer to be passed in to the jobsService.getJobsList(showClient); if I hard code jobsService.getJobsList(1); works perfect
                it is just receiving the string clientID instead of its value
                CustomClientClass.as
                package events
                {
                import flash.events.Event;

                public class CustomClientClass extends Event
                {
                public var customClientID:String;

                public function CustomClientClass(customClientID:String,type:String)
                {
                super(type);
                this.customClientID = customClientID;
                }

                override public function clone():Event
                {
                return new CustomClientClass(customClientID, type);
                }
                }
                }
                the code for jobs component.
                • 5. Re: Passing data to components
                  atta707 Level 2
                  okay, let's try this:

                  1) change public var showClient:String to private scope and rename it to let's just say _showClient
                  2) create two functions for property public function set showClient(id:String):void and public function get showClient(): String
                  3) in your public function set showClinet() you'll first set the value of private variable _showClient and then call init() method which would in turn read the _showClient and send the request.

                  That should work!

                  • 6. Re: Passing data to components
                    Imagine8 Level 1
                    I have now added I have only shown the new code.
                    [Bindable]
                    private var _showClient:String;
                    [Bindable]
                    private var myJobs:ArrayCollection;
                    public function set showClient(value:String):void
                    {
                    _showClient= value;
                    }
                    public function get showClient():String
                    {
                    return _showClient;
                    }
                    public function init():void
                    {
                    jobsService.getJobsList(_showClient);
                    }
                    in the jobs component.

                    my problem still seems to lie in the way the component is called in the main app file

                    <comps:jobs id="jobsView" showClient="{clientID}"/> still throws an error with invalid data type when passing clientID to the cfc.(it is passing the literal text cleintID still)
                    If i hard code like this it all works fine.
                    <comps:jobs id="jobsView" showClient="{2}"/>
                    I dont understand how to output the value of client ID not the literal string
                    I really appreciate your help with this.

                    Regards
                    Jamie
                    • 7. Re: Passing data to components
                      atta707 Level 2
                      there is one little detail missing, add the call to init() function in your property setter:

                      public function set showClient(value:String):void
                      {
                      _showClient= value;
                      init();
                      }
                      • 8. Re: Passing data to components
                        Imagine8 Level 1
                        Thanks for your help.
                        You are a champion :)