Announcement Announcement Module
Collapse
No announcement yet.
Using prana to help build an item renderer at runtime... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using prana to help build an item renderer at runtime...

    I've used prana for many tricky things before (I'll have to post some of my more recent cleverness from my prana / puremvc experiences) - but one thing I'm facing now is this:

    I've got a a datagrid that has columns that are defined by data at runtime, and these columns have an item renderer / editor that is defined by additional data at runtime. (For instance, a given datagrid could be loaded with columns representing geographic regions and a time-period column - and if a dataset has 5 regions - there would be 5 columns of regions and 1 column showing a date range or something) - now each of these columns needs to have a combobox or some data-driven control to make selections for that region... (lets say it's for scheduling)

    So I have a simple method that I created to make it easier to get my columns set up:
    Code:
    public function get dataGridColumns():Array {
    	var columns:ArrayCollection = new ArrayCollection();
           // time period column is created in another method - but
           // it is just a simple column that defines how to render the time
           // data
    	columns.addItem(timePeriodColumn);
    	if (region != null && region.length > 0) {
    		// iterate over all the the regions add columns for each of them
    		for each (var s:Object in region) {					
    			var column:DataGridColumn = getRegionColumn(s as RegionVO);
    			columns.addItem(column);
    			}						
    		}
    		return columns.source;
       }
    The method that this one calls into is where I am trying to figure out if I can leverage Prana (or Spring AS3 now) / pureMVC to help me out:

    Code:
     protected function getSitegroupColumn(site:SiteGroupVO):DataGridColumn {
    	var c:DataGridColumn = new DataGridColumn(site.name);
    	c.itemRenderer = new ClassFactory(scheduledItemRenderer);
    	(c.itemRenderer as ClassFactory).properties = {region: Region};
    	c.sortable = false;
    	return c;						
    }
    The ClassFactory works ok - but what it doesn't do well is it doesn't provide my a way to cleanly tell the renderer where to get the data to populate the combobox from.

    Does Prana have an easy utility to specify a config name and have it return a ClassFactory so I could create a prototype object in the config file and then have Prana be responsible for returning it? I'd much rather do my dirty work in Prana (or Spring now, sorry) than relying on ClassFactory.

    Ryan

    PS: Christophe - I never signed / sent in those papers... woops. PM me and tell me what I need to do to get those to you

  • #2
    Ok. Solved my own problem (I think)

    I looked at the IFactory instance in Flash - and all it has is one method - newInstance():* - which makes it really easy to make an IFactory that I can use to use with Prana:

    Code:
    package org.pranaframework.ioc.utils
    {
    	import mx.core.IFactory;
    	import mx.logging.ILogger;
    	import mx.logging.Log;
    	
    	import org.pranaframework.ioc.factory.IObjectFactory;
    
    	public class ContextRetrievalFactory implements IFactory
    	{
    		// the name of the object to retrieve from the config file
    		public var contextConfigName:String;
    		
    		// the container object factory
    		public var objectFactory:IObjectFactory;
    		
    		// the arguments that are used to retrieve the objet
    		public var constructorArguments:Array = null;
    		
    		public function ContextRetrievalFactory(contextConfigName:String, objectFactory:IObjectFactory)
    		{
    			this.contextConfigName = contextConfigName;						
    			this.objectFactory = objectFactory;
    		}
    
    		public function newInstance():*
    		{		
    			return getObject(this.contextConfigName, this.objectFactory, this.constructorArguments);
    		}
    		
    		// create an instance of the location delegate
    		protected static function getObject(s:String, container:IObjectFactory, constructorArguments:Array=null):* {						
    			logger.debug("ContextRetrievalFactory retrieving object from the application context for configName:" + s);		
    			return (container.getObject(s, constructorArguments));
    		}
    		
    		/************************************************************/
    		/* DEPENDENCY INJECTION & LOGGING						    */
    		/************************************************************/	
    		
    		private static var _logger:ILogger;
    		
    		private static function get logger():ILogger {
    			if (_logger == null) 
    				_logger = Log.getLogger("org.pranaframework.ioc.utils.ContextRetrievalFactory");
    			return _logger; 
    		}
    		
    	}
    }
    I'm pretty sure I don't have credentials for the new SVN - so someone else will have to commit this - I might tweak it a bit as I use it.

    Ryan
    Last edited by Ryan Gardner; Dec 8th, 2008, 11:04 PM. Reason: tweaking code

    Comment


    • #3
      Hi Ryan,

      have you looked into the IFactoryObject interface (in org.springextensions.actionscript.ioc.factory)? I think it could be useful for your use case.

      regards,
      Christophe

      Comment

      Working...
      X