5 Replies Latest reply on Feb 9, 2010 7:26 PM by ShankarFlex3

    Alert Box repeating

    ShankarFlex3 Level 2

      Hi All,

       

      I have posted the same under Flex Data Services but could not get any response, probably I am assuming most users visit Flex category.

       

       

      I am using the Cairngorm framework, Java for my online flex application. One of my screens has a search field, upon clicking enter an Event is dispatched and the corressponding Command class is called. This command class sends a RemoteObject request to one of the Java class methods which returns a list of items found.

       

      When there is an error returned the FaultEvent method catches it and throws and Alert message to the user.

       

      Now my problem is if any of the next search returns Fault, the Alert message pops up twice and keeps adding up every time a Fault is returned.

      So for ex: if 4 times the search fails, the Alert message pops up 4 times.

       

      This is very annonying and I am not able to figure it out exactly. Is it my code or something to do with Cairngorm?

       

      Please suggest.

       

       

      Thanks,

      Shankar.

        • 1. Re: Alert Box repeating
          harihisu

          Can you share your SearchCommand and SearchDelegate class?

          • 2. Re: Alert Box repeating
            ShankarFlex3 Level 2

            Hi,

             

            I am not using a Delegate class, just attaching the command class.

             

            Thanks

            • 3. Re: Alert Box repeating
              harihisu Level 2

              The problem is about resource management. You add listeners without removing them after task done.

              In Cairngorm, to handle each dispatched event, FrontController will create a new command of corresponding CommandClass. First time you dispatch the search event, command1 will be generated to execute and listen to ResultEvent as well as FaultEvent, but after all the listeners still remain. Next time you dispatch the search event, command2 will be generated and once again addEventListener to the remoteObject. From now, whenever a fault event happens, both command1 and command2 executes their own event handling functions.

               

              To solve this problem, you can either

              _ Call removeEventListeners when the command is no longer needed,

              _ Split this command into several subCommand, each command implements IResponder interface and handles one AbstractOperation. Use the following code lines instead of add listeners directly to the Operation

               

              var estOp:AbstractOperation = remoteService.getOperation("getEstimators");
              var call:AsyncToken = estOp.send();
              call.addResponder( this ); // this here is the subCommand instance, which has result(event) and fault(event) methods
              
              1 person found this helpful
              • 4. Re: Alert Box repeating
                ShankarFlex3 Level 2

                Hi,

                 

                I am working on your suggestion, will get back once done...

                 

                Message was edited by: ShankarFlex3

                • 5. Re: Alert Box repeating
                  ShankarFlex3 Level 2

                  Hi,

                   

                  The code works perfectly after the changes.

                   

                   

                  Thanks,

                  Shankar.