Announcement Announcement Module
Collapse
No announcement yet.
How do I define a spring config statically? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I define a spring config statically?

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

    Code:
    <?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.AdminPresentationModel"/>
            </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:-

    Code:
    <?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.AdminPresentationModel"/>
            </objects>
        </mx:XML>
    
    </mx:Application>
    .. or, better still, using MXML's "default property" concept so that you could do something like this:-

    Code:
    <?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.AdminPresentationModel"/>
            </objects>
        </spring:FlexXMLApplicationContext>
    
    </mx:Application>
    Thoughts?

  • #2
    good ideas

    Hey there,

    this seems like an interesting alternative, maybe you can add a feature request in Jira? This way features are collected in a centralized way and have more chance of being implemented eventually.
    Thanks a lot,

    Roland

    Comment


    • #3
      Done

      http://jira.springframework.org/brow...IONSCRIPTAS-39

      Comment


      • #4
        This is something we will definitely consider. I didn't have that in mind for the roadmap of 1.0, but we will briefly look into it and perhaps try to add support for it. If not in 1.0, it will certainly be on our list.

        Comment

        Working...
        X