3 Replies Latest reply on Feb 4, 2009 6:37 AM by injpix

    Cairngorm & Problems with Shared Components

      Thanks in advance for any help. I still consider myself a newbie, so please excuse any stupid errors that I make in describing the problem I am having.

      I am working on a Cairngorm app, the framework of which has been handed to me. I have a component that can be used to either enter or "update". Update is in quotes because what really happens is that the old record is voided and a new one is entered -- but the user is oblivious to this.

      This component, which wraps and submits the data, is instantiated twice in the app. Each instantiation is accessed via a different "link". The problem: each time the user enters or "updates", 2 records entered. I watch it in debug, two RPC's and two results. I assume that this is because the component is instantiated twice and, for the life of me, I cannot figure out how to prevent this. I

      I have tried a couple of things 1) created two sets of events (Cairngorm & Completion), one for submit and one for modify, but because the command expects a Cairngorm event of a certain type, it can't handle both without a bunch messing around. I tried using one initial Cairngorm event (submit) and two distinct completion events, but no go. I am thinking about now creating two commands .... ???

      Actually, this is not a new problem. I am a bit under the gun here, so when it came up before, I duplicated all the code, including everything related to RPCs (DTOs, commands, etc.) but this is becoming a nightmare to maintain and is bad, bad, bad ....

      Any suggestions? This cannot be a completely uncommon thing?

        • 1. Re: Cairngorm & Problems with Shared Components
          injpix Level 3
          I am not sure why you need to instantiated the component twice. A component can broadcast several different events of the same Type. For an example:

          broadcaster.broadcastEvent(WidgetEvent.ENTER, new WidgetEvent(widgetVo));
          broadcaster.broadcastEvent(WidgetEvent.UPDATE, new WidgetEvent(widgetVo));

          Are you sure the component doesn't broadcastEvent 2 calls for a each click? Perhaps one is being fired off in a subclass and the other in the super class?

          "...but because the command expects a Cairngorm event of a certain type..."

          The command expects a Event Type. Cairngorm will deserialize your custom event into a Event type with the following properties:

          public var type:String;
          public var data:Object;

          So the data will property will hold your custom Event. And you would set that as an instance var in the command.
          • 2. Re: Cairngorm & Problems with Shared Components
            JeffryHouser Level 4

            It's not that odd to use the same component twice in different. For example, have you ever used more than one VBox or Form or ViewStack or Canvas in an app? Or on the less visual side, how about ArrayCollections or XML?


            w/o seeing code, I can't say whether or not the problem is due to the component being instantiated twice. I think it is unlikely that just having two instances would cause two remote calls. I'd look for something inside the component that is causing the second call.
            • 3. Re: Cairngorm & Problems with Shared Components
              injpix Level 3
              I agree with the examples you have posted JeffHouser. But I was under the assumption that the component (one instance) serves 2 purposes; one for 'entering' new data and the other for 'updating' existing data.