Announcement Announcement Module
Collapse
No announcement yet.
Placeholder Help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Placeholder Help

    I'm using SAS 1.1 and I can not seem to get property placeholders to work and it must be something simple I'm not doing because it's to obvious for it not to work. I have a very simple application that loads an application context and then traces out the properties in it and it doesn't work. I even tried creating another class and autowireing values to it and it doesn't seem to replace the placeholders.

    Here is my application file:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/mx"
                           creationComplete="handleCreationComplete()">
    	<fx:Script>
    		<![CDATA[
    			import org.springextensions.actionscript.context.support.FlexXMLApplicationContext;
    			import org.test.MyClass;
    			
    			private var _applicationContext:FlexXMLApplicationContext;
    			
    			protected function handleCreationComplete():void
    			{
    				trace("Loading xml");
    				_applicationContext = new FlexXMLApplicationContext("application-context.xml");
    				_applicationContext.addEventListener(Event.COMPLETE, complete_handler);
    				_applicationContext.load();
    			}
    			
    			protected function complete_handler(event:Event):void {
    				trace("Loaded xml");
    				_applicationContext.removeEventListener(Event.COMPLETE, complete_handler);
    				baseURL.text = _applicationContext.properties.getProperty("baseURL");
    				trace("Base URL" + _applicationContext.properties.getProperty("baseURL"));
    				trace("S1: " + _applicationContext.properties.getProperty("s1"));
    				trace("S2: " + _applicationContext.properties.getProperty("s2"));
    				
    				var myObject:MyClass = _applicationContext.getObject("myObject");
    				
    				var resolver:PropertyPlaceholderResolver = new PropertyPlaceholderResolver();
    				resolver.properties = _applicationContext.properties;
    				resolver.resolvePropertyPlaceholders("s1");
    				
    
    				trace("S2: " + _applicationContext.properties.getProperty("s2"));
    			}
    		]]>
    	</fx:Script>
    	<s:Label x="10" y="10" text="Base URL:"/>
    	<s:Label id="baseURL" x="77" y="10" text=""/>
    	
    	
    </s:WindowedApplication>
    My application-context.xml file is
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <objects xmlns="http://www.springactionscript.org/schema/objects"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://www.springactionscript.org/schema/objects
                                            http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd">
    
        <property name="baseURL" value="http://www.example.com" />
        
        <property name="s1" value="First string and ${s2}"/>
        <property name="s2" value="Second string"/>
    
        <object id="myObject" class="org.test.MyClass">
          <property name="string1" value="${s1}"/>
          <property name="string2" value="${s2}"/>
          <property name="string3" value="string 3 value"/>
        </object>
    </objects>
    Any my autowired class is:
    Code:
    package org.test
    {
    	public class MyClass
    	{
    		[Autowired]
    		public var string1:String;
    		
    		[Autowired]
    		public var string2:String;
    		
    		[Autowired]
    		public var string3:String;
    		
    		[Autowired(externalProperty='s1')]
    		public var string4:String;
    	}
    }
    Nothing I have tried has been able to get "s1" to resolve to what I was expecting according to the documentation section 2.1.1.4. External property files
    I've been pulling my hair out with this so any help would be appreciated!

  • #2
    hm, this might be a bug actually.

    Have you tried putting the properties in an external file and checking if they are correctly loaded in that case?

    cheers,

    Roland

    Comment


    • #3
      Roland, thanks for your help!

      Putting the properties in an external config file semi-worked. First, it failed because it couldn't find FlexPropertyPlaceholderConfigurer which wasn't a big deal as I get around that as with everything else in SAS. Now, any properties that defined in an external file will resolve correctly to stuff that is auto-wired and other objects using the placeholders for values.

      However, any properties defined in the XML using <property name="s1" value="s1 value"/> throws a "Error: Could not resolve placeholder '${s1}'" when used somewhere.

      So, I'll just move all properties to an external file to get around it.

      Tracy

      Comment


      • #4
        Hey there,

        sorry about that, so it WAS a bug...
        I'll try and make sure that it'll work in the upcoming v2.0, I promise Soooo, many things to do though.... Beat with me hehe

        cheers,

        Roland

        Comment

        Working...
        X