ISwizAware: [PostConstruct] called but no injection

128 views
Skip to first unread message

doahh

unread,
May 16, 2012, 7:40:24 AM5/16/12
to Swiz Framework
Hello,

I have a class that implement the ISwizAware interface and correctly
gets the ISwiz Object injected into it:

private var _iSwiz:ISwiz;
public function set swiz(iSwiz:ISwiz):void {
this._iSwiz = iSwiz;
}

it then goes on to create a PopUp using the following code:

var dialogPrint:DialogPrint =
PopUpManager.createPopUp(FlexGlobals.topLevelApplication as
DisplayObject ,
DialogPrint , true) as DialogPrint;
_iSwiz.registerWindow(dialogPrint);

When the registerWindow(.) method is called, the [PostConstruct] in
the dialogPrint instance is called, but on accessing an [Inject]'ed
property, that property is null:

=== DialogPrint.mxml ===

[Log] public var logger:ILogger;
[PostConstruct]
public function init():void {
logger.debug("Entered function init"); // This is null
}

Can anyone tell me what I am doing wrong?

João Fernandes

unread,
May 16, 2012, 7:52:09 AM5/16/12
to swiz-fr...@googlegroups.com
Usually what I do is 

1) have swiz source path added to the swiz-framework.swc so I can step into the source code and see what might be failing.
2) usually define a property as getter/setter so if the setter isn't being called, something is wrong and swiz isn't unable to process your dependency.

Also check if your dependency is a public (or behind a namespace) variable.

João Fernandes


--
You received this message because you are subscribed to the Google Groups "Swiz Framework" group.
To post to this group, send email to swiz-fr...@googlegroups.com.
To unsubscribe from this group, send email to swiz-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/swiz-framework?hl=en.




--

João Fernandes

doahh

unread,
May 16, 2012, 11:43:50 AM5/16/12
to Swiz Framework
Thanks for the response, but I am not sure I understand what you have
suggested.

I tried adding the Swiz source code, but I am using FlashDevelop and
it won't compile my app with the source code added to the classpath. I
will post to the FlashDevelop forum and ask there about this.

I added a getter and a setter into DialogPrint.mxml for the logger
property, it didn't get called.

It seems strange to me, [Inject] is supposed to be called before
[PostConstruct], but it seem to be ignored.

I upgraded from Swiz-1.0RC2 to 1.4, but that didn't fix anything. Can
someone help further?




On May 16, 12:52 pm, João Fernandes

doahh

unread,
May 16, 2012, 12:11:36 PM5/16/12
to Swiz Framework
Looking through the source for Swiz, and putting in some trace
statement, it seems as it the [Log] metadata tag is not being
processed for some reason. Here is the my trace from
BaseMetaDataProcessor.setUpMetadataTags(..):

Setting up metadata tag [Inject] for bean [Bean{ source:
DialogPrint9395, name: null }]
Setting up metadata tag [Inject] for bean [Bean{ source:
DialogPrint9395, name: null }]
Setting up metadata tag [Inject] for bean [Bean{ source:
DialogPrint9395, name: null }]
Setting up metadata tag [Inject] for bean [Bean{ source:
DialogPrint9395, name: null }]
Setting up metadata tag [Dispatcher] for bean [Bean{ source:
DialogPrint9395, name: null }]
Setting up metadata tag [PostConstruct] for bean [Bean{ source:
DialogPrint9395, name: null }]

The [Log] tag is never processed which results in the logger being
null. If I comment out the logger in my DialogPrint, then it get past
my initial error, but falls over later when another Object in
DialogPrint uses the [Log] tag. To me this appears to be a Swiz bug,
but I could be doing something else silly?

João Fernandes

unread,
May 16, 2012, 12:14:21 PM5/16/12
to swiz-fr...@googlegroups.com
Are you adding the "Log" entry to the -keep-as3-metadata compiler argument?

doahh

unread,
May 16, 2012, 12:21:51 PM5/16/12
to Swiz Framework
Not that I am aware of, these are my compiler arguments:

-locale=en_US,fr_FR
-source-path+=src/l10n/locale/{locale}



On May 16, 5:14 pm, João Fernandes

doahh

unread,
May 16, 2012, 12:27:02 PM5/16/12
to Swiz Framework
I changed it to:

-locale=en_US,fr_FR
-source-path+=src/l10n/locale/{locale}
-keep-as3-metadata+=Log

but it didn't help. I don't have any trouble with the [Log] metadata
tag in the non-PopUp components, just when it is called through
registerWindow(dialogPrint).

Brian Kotek

unread,
May 16, 2012, 1:06:35 PM5/16/12
to swiz-fr...@googlegroups.com
If you have an issue with the [Log] custom processor, you'll really have to talk to the creator of that custom processor, since it isn't part of the core Swiz framework.

doahh

unread,
May 16, 2012, 1:32:59 PM5/16/12
to Swiz Framework
Of course, I had forgotten that it was not a part of the Swiz
framework. I do apologise and thank you for your point.

Dustin Mercer

unread,
Mar 24, 2013, 2:39:22 PM3/24/13
to swiz-fr...@googlegroups.com
I also had this issue, with a custom processor I created.  It's a bug with swiz where it doesn't pass the custom processors into the child swiz it creates when registering a window.  The fix is in the swiz class, init method.  I've copied the code below:

if( parentSwiz != null )
{
_beanFactory.parentBeanFactory = _parentSwiz.beanFactory;
if( domain == null )
domain = parentSwiz.domain;
globalDispatcher = parentSwiz.globalDispatcher;
config.eventPackages = config.eventPackages.concat( _parentSwiz.config.eventPackages );
config.viewPackages = config.viewPackages.concat( _parentSwiz.config.viewPackages );
                                //Added to fix bug with custom processors not being passed to child instances
customProcessors = _parentSwiz.processors;
Reply all
Reply to author
Forward
0 new messages