Problem injecting by name

27 views
Skip to first unread message

Loïc Fougeray

unread,
May 28, 2010, 5:13:14 AM5/28/10
to Swiz Framework
Hi, i just stumbled upon a weird behavior when i tried to inject a
bean property. I get the following error :
Error: InjectionProcessorError: bean not found:
applicationModel.version. It seems i cannot acces my bean with its ID.
On BeanProvider initialization, setBeanIds doesn't find the bean's id
i wrote in my bean declaration.

I find this very disturbing since it's a basic feature, my guess is i
must be doing something wrong but i can't find what it is. I'd
appreciate some help ^^

Here are peaces of code that produce the error :

--------------------------------------------------------------------------------
code : NamedBean.mxml
--------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:swiz="http://swiz.swizframework.org"
xmlns:models="models.*"
xmlns:local="*">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
]]>
</mx:Script>

<swiz:Swiz>
<swiz:config>
<swiz:SwizConfig setUpEventType="{FlexEvent.PREINITIALIZE}"/>
</swiz:config>

<swiz:beanProviders>
<swiz:BeanProvider>
<models:ApplicationModel id="applicationModel"/>
<local:SomeBean/>
</swiz:BeanProvider>
</swiz:beanProviders>
</swiz:Swiz>
</mx:WindowedApplication>

--------------------------------------------------------------------------------
code : SomeBean.as
--------------------------------------------------------------------------------
public class SomeBean
{
[Inject("applicationModel.version")]
public var appVersion:String;
}

--------------------------------------------------------------------------------
code : ApplicationModel.as
--------------------------------------------------------------------------------
import flash.desktop.NativeApplication;

[Bindable]
public class ApplicationModel implements IApplicationModel
{
private var _version:String;

public function get version():String
{
return _version;
}

public function set version(val:String):void
{
_version = val;
}

public function ApplicationModel()
{
var appXml:XML =
NativeApplication.nativeApplication.applicationDescriptor
var ns:Namespace = appXml.namespace();
version = appXml.ns::version;
}

}

--------------------------------------------------------------------------------
code : IApplicationModel.as
--------------------------------------------------------------------------------
[Bindable]
public interface IApplicationModel
{
function get version():String;
function set version(val:String):void;
}

ben.clin...@gmail.com

unread,
May 28, 2010, 8:29:22 AM5/28/10
to swiz-fr...@googlegroups.com
Hi Loic,

When defining BeanProvider inline, you have to wrap the actual instance in a Bean tag and use the name attribute. This is necessary because the id attribute is always scoped to the containing document, which is WindowedApplication in your case.

You can either define the bean like <Bean name="appModel"><AppModel /></Bean> or you can define your BeanProvider in its own file where it is the root tag.

HTH,
Ben




--
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.


Loïc Fougeray

unread,
May 28, 2010, 9:14:33 AM5/28/10
to Swiz Framework
Thanks it's now working, since i already have a special mxml component
for Swiz i'll be using <Bean> for the few named beans i have.
I don't think i've seen anything about that on the wiki.

On 28 mai, 14:29, "ben.clinkinbe...@gmail.com"
<ben.clinkinbe...@gmail.com> wrote:
> Hi Loic,
>
> When defining BeanProvider inline, you have to wrap the actual instance in a
> Bean tag and use the name attribute. This is necessary because the id
> attribute is always scoped to the containing document, which is
> WindowedApplication in your case.
>
> You can either define the bean like <Bean name="appModel"><AppModel
> /></Bean> or you can define your BeanProvider in its own file where it is
> the root tag.
>
> HTH,
> Ben
>
> > swiz-framewor...@googlegroups.com<swiz-framework%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages