10 Replies Latest reply on Aug 5, 2008 10:44 AM by jonesf

    Multiple event handlers for a single RemoteObject  method?

    jonesf
      I want to bind comboboxes to results returned from two calls on a single remote method. These two comboboxes have different items, but they are both populated by the same remote method (method parameters determine the data returned). So they need to have different handlers for this remote method, so that I know which combobox to bind which result to. But it seems that operations on RemoteObject's are keyed by method name. In other words, each remote method can only have a single actionscript handler. But upon getting the result, I have no idea which request I'm receiving for which combobox. So what I'm trying to do seems impossible.... although I'd find that hard to believe.

      Am I missing something? Any ideas?
      Thanks
        • 1. Re: Multiple event handlers for a single RemoteObject  method?
          jonesf Level 1
          So, it just occurred to me that I'm reusing the same remoteobject for the request and I could work around the problem by creating a new remoteobject for each request. I thought this would be inefficient which is why I did not set it up like that originally. But maybe it's not big deal.
          • 2. Re: Multiple event handlers for a single RemoteObject  method?
            cheftimo Level 2
            Having two RemoteObjects seems really strange/wasteful.

            Why couldn't you just add a new method to the CFC? Then you would have two methods, each one returning the data each ComboBox needs.

            Carlos
            • 3. Re: Multiple event handlers for a single RemoteObject  method?
              jonesf Level 1
              Hi Carlos,
              Thanks for the response.
              This is just one small sample of a larger problem. This is a big application with many comboboxes, queries, etc. Sometimes I set up a method that takes a type of query string and it can serve many different functions on the client. I could set up a method of every little grain in my flex app, but I prefer not to do it that way. For what I'm doing, that would be very cumbersome.
              • 4. Re: Multiple event handlers for a single RemoteObject  method?
                cheftimo Level 2
                Not as cumbersome as setting up multiple RemoteObjects to use the same CFC. The best thing to do would be to get all your data into an Array, then do your sorting, filtering, whatever on the client. Although not the same situation, here is a similar one, from which you should get some ideas: http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=585&threadid =1378895&highlight_key=y.

                Carlos
                • 5. Re: Multiple event handlers for a single RemoteObject  method?
                  Gregory Lafrance Level 6
                  How about just access the id of the combobox in the method, then you know which gets what.
                  • 6. Re: Multiple event handlers for a single RemoteObject  method?
                    jonesf Level 1
                    Greg,
                    Do you mean add an extra parameter to my server side method to accept the element ID from the client, then also return this ID in the result? If so, that could certainly work. Thanks for the suggestion.

                    Here's another idea I had. Please tell me if you see any potential issues with this...
                    Create a map of AsyncTokens to the relevant combobox. So, for each request, I'd store the request (AsyncToken) as a map key with a value that is a component or some other identifier that tells me what it is meant for. I'm surprised there's no simple way to attach metadata with a request for later use... but this seems to accomplish that. What do you guys think?



                    • 7. Re: Multiple event handlers for a single RemoteObject  method?
                      Gregory Lafrance Level 6
                      I've never tried what you describe, so I can't comment on it. Sorry... :-(
                      • 8. Re: Multiple event handlers for a single RemoteObject  method?
                        cheftimo Level 2
                        No offense to anyone. Here's my newbie 2 cents;

                        I still think the best would be to bring the data into Flex, say, into an ArrayCollection. Then, once Flex has it, it can be sorted, filtered or otherwise manipulated to populate the ComboBoxes and whatever else you need to populate – based on Flex IDs or other variables that the server does not need to know about or deal with.

                        I tend to not have the server do things that Flex can do – to keep the calls to the server to the minimum and as short as possible.

                        It would be interesting to hear what other forum participants have to say about this.

                        Anyone?

                        Carlos
                        • 9. Re: Multiple event handlers for a single RemoteObject  method?
                          Michael Borbor Level 4
                          Hi Carlos, I think what jonesf suggested is the right way to go; you could implement it like this too:

                          <mx:Script>
                          <![CDATA[
                          import mx.collections.ArrayCollection;
                          import mx.rpc.AsyncToken;
                          import mx.rpc.events.ResultEvent;
                          private var token:AsyncToken;

                          [Bindable]
                          private var myArray1:ArrayCollection= new ArrayCollection();

                          [Bindable]
                          private var myArray2:ArrayCollection= new ArrayCollection();

                          private function doFirstFunction():void{
                          token = RO.GetQuote("arg1","arg2")
                          token.action = "combo1";

                          }

                          private function doSecondFunction():void{
                          token = RO.GetQuote("arg1","arg2","arg3")
                          token.action = "combo2";

                          }

                          private function rslHandler(event:ResultEvent):void{
                          token=event.token;
                          if (token.action=="combo1") {
                          myArray1=event.result as ArrayCollection;
                          }
                          else if (token.action=="combo2"){
                          myArray2=event.result as ArrayCollection;
                          }

                          }

                          ]]>
                          </mx:Script>

                          <mx:RemoteObject id="RO" destination="MyRemoteObjectDest"
                          fault="Alert.show(event.fault.faultstring), 'Error'" result="rslHandler(event)">

                          <mx:method name="GetQuote">
                          </mx:method>
                          </mx:RemoteObject>

                          Then you just need to add a button ror a custom event, and so on. in order to trigger action1 or action2.

                          I hope this could help you.
                          • 10. Re: Multiple event handlers for a single RemoteObject  method?
                            jonesf Level 1
                            mab_bond,
                            Thanks for the suggestion. Interesting though.. I *thought*I had tried something similar to that and it threw a runtime exception saying that I could not assign an arbitrary/dynamic property to the AsyncToken object. Maybe I'm wrong though, I'll try it again. I haven't done anything with this issue since my last post has I've been battling memory leak issues :-( Hopefully soon though.


                            Carlos,
                            What you're saying makes sense in some cases, but does not really apply to me. I can't/shouldn't load my whole database into Flash and do sorting, filtering and processing there. I saw your link, and the comparison is apples & oranges. In your case, you're loading data from a db and putting it in a grid and paging, sorting, etc. Loading that into memory and performing those functions is fine in some cases... just depends on how much data it is. But regardless... not really applicable to this thread. I do appreciate your feedback though.