4 Replies Latest reply on Apr 15, 2011 2:02 AM by yderidde

    ModuleMessageInterceptor Question

    anuj_gakhar

      I am using Parsley 2.3 in a Flex 4 Project. My  requirement is to pre-load a module after the user successfully logs in  to the app. The user may or may not click on the link that opens the  module visually but the idea is to have it ready as soon as the user  logs in. 

      I am using ParsleyModuleDescriptor in the Main App Context to define the  Module. And then I also have a ModuleMessageInterceptor in the Context  which if I understand correctly, loads the module if it hasn't already ?  

      So, 

      1) User logs in
      2) I dispatch a Parsley message (LoginCompleteMessage)
      3) LoginCompleteMessage is setup in the Context in the ModuleMessageInterceptor.
      <module:ModuleMessageInterceptor type="{LoginCompleteMessage}"
      moduleRef="documentsModule"/>
      4) DocumentsModule is setup to listen to this message with the [MessageHandler] metatag.

      But nothing happens - the module never gets loaded post-login. The  ModuleMessageInterceptor only works if the module has already been  loaded.

      What am I missing here?

      Thanks in advance for the help.

        • 2. Re: ModuleMessageInterceptor Question
          yderidde

          Hi,

          sorry for the delay

           

          First of all, I would definitely recommend you to read carefully the how-to documentation, you can find it here http://sourceforge.net/adobe/cairngorm/wiki/HowToUseCairngormModule/

           

          So basically from what I understand you would like to have your module starting loading as soon as the user authenticated in your application.

           

          In order to achieve this you will have to use the LazyModuleLoadPolicy. In few words, this load policy will trigger the module loading as soon as a message with a specific type / id is dispatched.

           

          * let's say your module definition in the Parsley Context is:

           

          <cairngorm:ParsleyModuleDescriptor

                  objectId="moduleA"

                  url="example/moduleA/ModuleA.swf"

                  applicationDomain="{ ClassInfo.currentDomain }"

                  />

           

          * Assuming your message is a class of type "PingMessage", If you want your message to only trigger one specific instance of your module type you will have to specify a [ModuleId] in order for the C3 Module mechanism to know the specific instance in which it must dispatch that message.

          In this case you need to set the moduleId property of your ModuleViewLoader (here it is set to "myModuleInstance") so the PingMessage class will look something like this:

           

          public class PingMessage

          {

          ...

           

              [ModuleId]

              public var moduleId:String = "myModuleInstance"

          }

           

          * you will also need to define a ModuleMessageInterceptor in the Parsley Context as follow:

           

          <cairngorm:ModuleMessageInterceptor

          type="{ PingMessage }" />

           

           

          * Now we still have to define the LazyModuleLoadPolicy  in the Parsley Context and give the message class type to it so it knows which type of message triggers the lazy load:

           

          <cairngorm:LazyModuleLoadPolicy objectId="lazyLoadPolicy" type="{ PingMessage }" />

           

          * Last thing, is to give that LazyModuleLoadPolicy reference to your ModuleViewLoader:

           

          <fx:Script>

                  <![CDATA[

                      import com.adobe.cairngorm.module.ILoadPolicy;

                      import com.adobe.cairngorm.module.IModuleManager;

           

                      [Bindable]

                      [Inject(id="moduleA")]

                      public var moduleManager:IModuleManager;

           

                      [Bindable]

                      [Inject(id="lazyLoadPolicy")]

                      public var lazyLoadPolicy:ILoadPolicy;

                  ]]>

              </fx:Script>

           

               <module:ModuleViewLoader id="moduleLoader"

                  moduleId="myModuleInstance"

                  moduleManager="{ moduleManager }"

                  loadPolicy="{ lazyLoadPolicy }"/>

           

          This should work ... Good luck.

          • 3. Re: ModuleMessageInterceptor Question
            anuj_gakhar Level 1

            Thanks for your reply. I am sure I tried that and it didn't work. Would it be because my ModuleViewLoader is sitting inside a ViewStack ?

            • 4. Re: ModuleMessageInterceptor Question
              yderidde Level 1

              It should work even within a ViewStack.

              This said, it can also be a bug ... So if you can create a small test-case project so I can easily have a look.

              I would also recommend you to get the sample test project of the Module Lib as it shows a working example of the LazyLoadPolicy, from there you can easily tweak it to add a ViewStack and try to reproduce your issue.

              You can get the source code of the sample project here: http://opensource.adobe.com/svn/opensource/cairngorm3/trunk/libraries/ModuleTest/