sparky62
Mar 11th, 2009, 01:31 PM
The Spring ActionScript 0.7.1 documentation shows you how to load the Spring application config over the network at run-time. While I guess this is what you'll want to do some of the time, it also seems to make sense that some of the time you'll want to define the Spring config as an "embedded" resource in the code itself.
XMLApplicationContext provides a way to load static config with its addConfig method which works like this:-
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:spring="org.springextensions.actionscript.context.support. *"
creationComplete="this.onCreationComplete()"
>
<mx:Script>
<![CDATA[
private function onCreationComplete():void
{
this.appContext.addConfig(this.config);
this.appContext.load();
}
]]>
</mx:Script>
<spring:FlexXMLApplicationContext id="appContext"/>
<mx:XML id="config">
<objects xmlns="http://www.pranaframework.org/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.pranaframework.org/objects
http://www.pranaframework.org/schema/objects/prana-objects-0.7.xsd">
<object id="adminPresentationModel" class="com.graemeharker.admin.models.AdminPresentationMod el"/>
</objects>
</mx:XML>
</mx:Application>
While it feels a little clumsy declaring a FlexXMLApplicationContext in MXML and then having to call addConfig() and load() programatically from a creationComplete handler it works. Plus calling "load()" when you're not actually "loading" a resource it's not that intuitive.
It would be neat if there was a way of declaring a Spring configuration in MXML without having to explicitly call load() in ActionScript.
Perhaps like this:-
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:spring="org.springextensions.actionscript.context.support. *"
>
<spring:FlexXMLApplicationContext id="appContext" source="{this.config}/>
<mx:XML id="config">
<objects xmlns="http://www.pranaframework.org/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.pranaframework.org/objects
http://www.pranaframework.org/schema/objects/prana-objects-0.7.xsd">
<object id="adminPresentationModel" class="com.graemeharker.admin.models.AdminPresentationMod el"/>
</objects>
</mx:XML>
</mx:Application>
.. or, better still, using MXML's "default property" concept so that you could do something like this:-
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:spring="org.springextensions.actionscript.context.support. *"
>
<spring:FlexXMLApplicationContext>
<objects xmlns="http://www.pranaframework.org/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.pranaframework.org/objects
http://www.pranaframework.org/schema/objects/prana-objects-0.7.xsd">
<object id="adminPresentationModel" class="com.graemeharker.admin.models.AdminPresentationMod el"/>
</objects>
</spring:FlexXMLApplicationContext>
</mx:Application>
Thoughts?
XMLApplicationContext provides a way to load static config with its addConfig method which works like this:-
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:spring="org.springextensions.actionscript.context.support. *"
creationComplete="this.onCreationComplete()"
>
<mx:Script>
<![CDATA[
private function onCreationComplete():void
{
this.appContext.addConfig(this.config);
this.appContext.load();
}
]]>
</mx:Script>
<spring:FlexXMLApplicationContext id="appContext"/>
<mx:XML id="config">
<objects xmlns="http://www.pranaframework.org/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.pranaframework.org/objects
http://www.pranaframework.org/schema/objects/prana-objects-0.7.xsd">
<object id="adminPresentationModel" class="com.graemeharker.admin.models.AdminPresentationMod el"/>
</objects>
</mx:XML>
</mx:Application>
While it feels a little clumsy declaring a FlexXMLApplicationContext in MXML and then having to call addConfig() and load() programatically from a creationComplete handler it works. Plus calling "load()" when you're not actually "loading" a resource it's not that intuitive.
It would be neat if there was a way of declaring a Spring configuration in MXML without having to explicitly call load() in ActionScript.
Perhaps like this:-
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:spring="org.springextensions.actionscript.context.support. *"
>
<spring:FlexXMLApplicationContext id="appContext" source="{this.config}/>
<mx:XML id="config">
<objects xmlns="http://www.pranaframework.org/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.pranaframework.org/objects
http://www.pranaframework.org/schema/objects/prana-objects-0.7.xsd">
<object id="adminPresentationModel" class="com.graemeharker.admin.models.AdminPresentationMod el"/>
</objects>
</mx:XML>
</mx:Application>
.. or, better still, using MXML's "default property" concept so that you could do something like this:-
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:spring="org.springextensions.actionscript.context.support. *"
>
<spring:FlexXMLApplicationContext>
<objects xmlns="http://www.pranaframework.org/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.pranaframework.org/objects
http://www.pranaframework.org/schema/objects/prana-objects-0.7.xsd">
<object id="adminPresentationModel" class="com.graemeharker.admin.models.AdminPresentationMod el"/>
</objects>
</spring:FlexXMLApplicationContext>
</mx:Application>
Thoughts?