Spicefactory Forum Index Spicefactory
Discuss Spicefactory Open Source Projects
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reloading modules problem

 
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory - General Discussions
View previous topic :: View next topic  
Author Message
alvarov



Joined: 12 Nov 2009
Posts: 3

PostPosted: Thu Nov 12, 2009 6:56 pm    Post subject: Reloading modules problem Reply with quote

Hi

I'm having problems (re)building the module context when the module gets reloaded. The first time it is loaded, no error occurs.

I'm building the context on addedToStage event of the module, like this:

Code:

FlexContextBuilder.build(GalleryListContext,this);


When the module is unloaded, the context is destroyed (automatically).
But when I need to (reload) the same module again, I get this error (resumed):

Code:

Error: One or more errors processing CompositeContextBuilder:
 Error processing [object ActionScriptObjectDefinitionBuilder]: One or more errors in ActionScriptObjectDefinitionBuilder:
 One or more errors processing modules.screens.tv.galleryList.context::GalleryListContext:
 Error building object definition for [Property galleryModel in class modules.screens.tv.galleryList.context::GalleryListContext]: Error #1009: Cannot access a property or method of a null object reference.
 Error building object definition for [Property galleryMediator in class modules.screens.tv.galleryList.context::GalleryListContext]: Error #1009: Cannot access a property or method of a null object reference.
 Error building object definition for [Property _GalleryListContext_MxmlObjectDefinitionFactoryTag1 in class modules.screens.tv.galleryList.context::GalleryListContext]: Error #1009: Cannot access a property or method of a null object reference.
 Error building object definition for [Property datagrid in class modules.screens.tv.galleryList.context::GalleryListContext]: Error #1009: Cannot access a property or method of a null object reference.
 Error building object definition for [Property galleryService in class modules.screens.tv.galleryList.context::GalleryListContext]: Error #1009: Cannot access a property or method of a null object reference.
   at org.spicefactory.parsley.core.builder.impl::DefaultCompositeContextBuilder/handleErrors()[I:\Spicefactory\Parsley\parsley-core\org\spicefactory\parsley\core\builder\impl\DefaultCompositeContextBuilder.as:210]
   at org.spicefactory.parsley.core.builder.impl::DefaultCompositeContextBuilder/invokeNextBuilder()[I:\Spicefactory\Parsley\parsley-core\org\spicefactory\parsley\core\builder\impl\DefaultCompositeContextBuilder.as:170]
   at org.spicefactory.parsley.core.builder.impl::DefaultCompositeContextBuilder/invokeNextBuilder()[I:\Spicefactory\Parsley\parsley-core\org\spicefactory\parsley\core\builder\impl\DefaultCompositeContextBuilder.as:199]
   at org.spicefactory.parsley.core.builder.impl::DefaultCompositeContextBuilder/build()[I:\Spicefactory\Parsley\parsley-core\org\spicefactory\parsley\core\builder\impl\DefaultCompositeContextBuilder.as:159]
   at org.spicefactory.parsley.flex::FlexContextBuilder$/buildAll()[I:\Spicefactory\Parsley\parsley-flex\org\spicefactory\parsley\flex\FlexContextBuilder.as:77]
   at org.spicefactory.parsley.flex::FlexContextBuilder$/build()[I:\Spicefactory\Parsley\parsley-flex\org\spicefactory\parsley\flex\FlexContextBuilder.as:59]
   at modules.screens.tv.galleryList::GalleryList/initContext()[E:\workspaceFlex\AlertTV_FH\src\modules\screens\tv\galleryList\GalleryList.mxml:27]
   at modules.screens.tv.galleryList::GalleryList/___GalleryList_AlertModule1_addedToStage()[E:\workspaceFlex\AlertTV_FH\src\modules\screens\tv\galleryList\GalleryList.mxml:5]


Note: I'm using Parsley 2.1.0

Thanks in advance.
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 1488
Location: Cologne Germany

PostPosted: Fri Nov 13, 2009 10:49 am    Post subject: Reply with quote

Unfortunately the stacktrace is pretty generic (I'll improve that in later versions so that you also see the original cause which is currently hidden).
Could you reduce the problem at hand to a simple sample app and post the code and the config here? I need a way to reproduce the error, as I suspect that it only happens under certain circumstances. Thanks.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
alvarov



Joined: 12 Nov 2009
Posts: 3

PostPosted: Fri Nov 13, 2009 11:52 am    Post subject: Reply with quote

Hi

Thank you for your fast reply.

I'll try to simplify and explain with more detail. I'm using a ModuleManager to load modules. The code looks like this:

Code:

/**
       * Loads an AlertModule to the container passed as an argument
       * @param alertModuleTarget the place where to load the element
       * @param alertModule alertModule URL to load
       */        
      public function loadAlertModule(target:DisplayObjectContainer,alertModuleURL:String):void {         
         
         // Set the target
         screenTarget = target;
         
         // Get the module URL, add an event listener and ask to load the module
         screenModule = ModuleManager.getModule(alertModuleURL);
         screenModule.addEventListener(ModuleEvent.READY, alertModuleLoadedHandler);
         screenModule.load();
      } 
      
      /**
       * Module loaded handler
       */ 
      private function alertModuleLoadedHandler(e:ModuleEvent):void {
          
          // Remove element if it was created before
         if ( screenElement != null ) {
            mainController.alertModule.unloadModule();
            screenTarget.removeChild(screenElement);
         }
         
         // Attach element
         screenElement = screenTarget.addChild(screenModule.factory.create() as DisplayObject);
         
         // Create a global reference
         mainController.alertModule = screenElement as IAlertModule;         
         
         // Dispatch ready event
         var mle:ModuleLoadedEvent = new ModuleLoadedEvent(ModuleLoadedEvent.ALERTMODULE_LOADED,mainController.alertModule);
         dispatchEvent(mle);
      }      



My config is something like this:
Code:

<Object type="{GalleryLoadingAction}">
      <Property name="_model"
              idRef="galleryModel"/>
      <Property name="_service"
              idRef="galleryService"/>
   </Object>
   
   <Object id="galleryMediator" type="{GalleryListMediator}" />
   
   <Object id="galleryModel" type="{Model}" />
   
   <Object id="galleryService" type="{GalleryServiceMock}" />
   
   <Object id="datagrid" type="{AlertDataGrid}"/>


And the module code is something like this:
Code:

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<core:AlertModule xmlns:mx="http://www.adobe.com/2006/mxml"
   xmlns:core="core.interfaces.*"
   xmlns:components="components.*"
   addedToStage="initContext();"
   xmlns:view="modules.screens.tv.galleryList.view.*">
   
   <mx:Script>
      <![CDATA[
         import mx.core.Application;
         import org.spicefactory.parsley.core.context.Context;
         import events.DataLoadedEvent;
         import modules.screens.tv.galleryList.view.GalleryListView;
         import modules.screens.tv.galleryList.context.GalleryListContext;
         import org.spicefactory.parsley.flex.FlexContextBuilder;
         import core.constants.Constants;
         
         import nl.demonsters.debugger.MonsterDebugger;
         
         /**
          * Initialize context
          */
         private function initContext():void {
               
            FlexContextBuilder.build(GalleryListContext,this);
               dispatchEvent(new Event(Constants.CONFIGURE_IOC, true));
         }
               
         /**
          * Method invoked when module is loaded
          */
         override public function startModule():void {            
            
            
         }
         
         /**
          * Data Loaded event handler
          */
         [MessageHandler(selector="dataLoaded")]
         public function dataLoadedHandler(evt:DataLoadedEvent):void {
                  
            showModule();
            
         }
      ]]>
   </mx:Script>
   <view:GalleryListView id="ref"/>
</core:AlertModule>


And finally the view:
Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"
   xmlns:components="components.*"
   addedToStage="dispatchEvent(new Event(Constants.CONFIGURE_IOC, true));" xmlns:renderers="components.renderers.*">
   
   <mx:Script>
      <![CDATA[
         import nl.demonsters.debugger.MonsterDebugger;
         import model.Model;
         import core.constants.Constants;
         import core.interfaces.IGalleryMediator;
         import mx.events.ListEvent;
         
         /**
          * Injected - Mediator instance
          */
         [Inject]
         public var _mediator:IGalleryMediator;
         
         /**
          * Injected - Model instance
          */
         [Inject]      
         [Bindable]
         public var _model:Model;
         
         /**
          * Initializes view
          */
         [Init]
         public function init():void {
            
            _mediator.getGalleries();
         }
         
         /**
          * On item click handler
          */   
         private function itemClickHandler(event:Event):void {
            
            //_mediator.galleryClick(event);
         }
         
      ]]>
   </mx:Script>

   <components:AlertDataGrid itemClick="itemClickHandler(event)"
   id="dataGrid" width="100%" height="100%" dataProvider="{_model.galleries}"
   headerStyleName="dataGridHeader">
      <components:columns>
         <mx:DataGridColumn width="200">
            <mx:itemRenderer>
               <mx:Component>
                  <renderers:ImageItemRenderer width="200" fieldName="THUMB_URL"/>
               </mx:Component>
            </mx:itemRenderer>
         </mx:DataGridColumn>
         <mx:DataGridColumn width="280">
            <mx:itemRenderer>
               <mx:Component>
                  <renderers:TvDetailsRenderer mode="G"/>
               </mx:Component>
            </mx:itemRenderer>
         </mx:DataGridColumn>
      </components:columns>
   </components:AlertDataGrid>
   
   
</mx:Canvas>


So, the first time the module is loaded everything is working. When the module gets unloaded I see the traces that shows that the context has been destroyed. But later, when I need to reload the same module again, I get the error that I mentioned earlier.
Back to top
View user's profile Send private message
alvarov



Joined: 12 Nov 2009
Posts: 3

PostPosted: Mon Nov 16, 2009 5:42 pm    Post subject: Reply with quote

I've been trying to solve this problem, but didn't have results (yet, I hope).

One thing that I've tried and didn't work (got the same error) was the CompositeContextBuilder to merge the module context to the root context. This isn't the ideal approach, but didn't work either.

I must be doing something wrong...

One thing that I didn't mentioned earlier and maybe is important, is that my modules are loaded by one main module (which has the root context). This main module represents my "application". It will be loaded by several applications that don't even use Parsley.

I hope somebody can help, because I'm blocked.
Back to top
View user's profile Send private message
jimp



Joined: 14 Nov 2009
Posts: 15
Location: San Francisco

PostPosted: Tue Nov 17, 2009 7:08 am    Post subject: Reply with quote

Hi Alvarov, no help from me as I have a similar problem. My situation is as follows.

I have an s:Window that I call open() on which, on creationComplete does a loadModule. The module calls FlexContextBuilder.build(Module3Context,this) in its preinitialize, where Module3Context only contains a PM (presentation model) object (not described here).

I can open the window with the module a first time. I close but don't unload the module. When I open the window the 2nd time I get the error, which is related to the PM object:
Error building object definition for [Property _Module3Context_Module3PanelPM1 in class test.module3::Module3Context]: Error #1009: Cannot access a property or method of a null object reference.

Related to this, I can't find an event to hang some init code off of in a component that is within the module. This should run every time the component is shown. creationComplete only happens when the module is 1st created, and not when the window is opened a 2nd time. This is not quite a Parsley question, but it does relate because I have to make sure Parsley has done its init. I wonder if anyone has ideas?

I've only been working with Parsley for about a week, so apologies if these questions seem wasteful. My test code is shareable, if it helps.
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 1488
Location: Cologne Germany

PostPosted: Tue Nov 17, 2009 12:22 pm    Post subject: Reply with quote

The problem with these issues is that there is no general problem with loading and unloading modules. I have a very basic Hello-World-style test app that works just fine. So it must be something where a specific set of features is used in a specific scenario. Therefore it would be great if someone could create a Jira ticket and add a complete FDT or FlexBuilder project as an attachment that reproduces the problem. As soon as I can reproduce it should be easy to fix it. alvarov posted some sample code, but there are still some pieces missing which might be relevant to see the error.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory - General Discussions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group