Packagecom.adobe.cairngorm.view
Classpublic class ViewLocator

The ViewLocator is a singleton class, that is used to retreive ViewHelper classes that can manipulate (get/set/switch) the user interface of a Cairngorm RIA.

Model-View-Controller (MVC) best practices specify that command classes should interact with the view using the model (see the ModelLocator class), but in some instance, command classes may require the assistance of ViewHelpers to get/set the user interface associated with the work they are designed to perform. ViewHelper classes contain methods that allow them to interrogate (get) individual elements of the view, such as the values of form fields, and to update the user interface, such as setting the data provider on DataGrids or Listcomponents. Additionally, a command may choose to toggle the user interface from one view to another - for instance, to take the user to a checkout screen.

The ViewLocator class is used to allow commands to instantly retrieve the appropriate ViewHelper. A command need only know the canonical name of a ViewHelper and the ViewLocator will return an instance of the appropriate ViewHelper class. In this way, command classes can manipulate the View irrespective of its implementation.

See also

com.adobe.cairngorm.model.ModelLocator
com.adobe.cairngorm.view.ViewHelper
com.adobe.cairngorm.commands.ICommand


Public Methods
 MethodDefined by
  
The ViewLocator constructor should only be created through the static singleton getInstance() method.
ViewLocator
  
[static] Singleton access to the ViewLocator is assured through the static getInstance() method, which is used to retrieve the only ViewLocator instance in a Cairngorm application.
ViewLocator
  
getViewHelper(viewName:String):ViewHelper
Retrieves the ViewHelper instance that has previously been registered with viewName.
ViewLocator
  
register(viewName:String, viewHelper:ViewHelper):void
Registers a viewHelper under a canonical viewName.
ViewLocator
  
registrationExistsFor(viewName:String):Boolean
Returns whether a view has been registered with a canonical name.
ViewLocator
  
unregister(viewName:String):void
Unregisters a viewHelper using its canonical name.
ViewLocator
Constructor detail
ViewLocator()constructor
public function ViewLocator()

The ViewLocator constructor should only be created through the static singleton getInstance() method. ViewLocator maintains a hash map of ViewHelpers, keyed on viewName with a particular view as the value stored in the hash map.

Method detail
getInstance()method
public static function getInstance():ViewLocator

Singleton access to the ViewLocator is assured through the static getInstance() method, which is used to retrieve the only ViewLocator instance in a Cairngorm application.

Wherever there is a need to retreive the ViewLocator instance, it is achieved using the following code:

       var viewLocator:ViewLocator = ViewLocator.getInstance();
       

Returns
ViewLocator
getViewHelper()method 
public function getViewHelper(viewName:String):ViewHelper

Retrieves the ViewHelper instance that has previously been registered with viewName.

Parameters
viewName:String — The name of the view for which we wish to retrieve a ViewHelper, eg "login"

Returns
ViewHelper
register()method 
public function register(viewName:String, viewHelper:ViewHelper):void

Registers a viewHelper under a canonical viewName.

In order that the application developer need not know the implementation of the view, a ViewHelper capable of manipulating a given view is registered under a simple canonical name.

For example, a LoginViewHelper may allow the manipulation of a Login window, that may start life as a PopUpWindow, but later be changed to a screen in a ViewStack. By registering the LoginViewHelper with the viewName "login", then any code that fetches the ViewHelper by it's name "login", and then calls methods on the ViewHelper, is completely insulated from any changes in the implementation of the view, and the implementation of the ViewHelper.

If a view is already registered with the canonical name, and Error is thrown.

Parameters
viewName:String — A simple canonical name for the view that the ViewHelper will manipulate, eg "login"
 
viewHelper:ViewHelper — An instance of a ViewHelper
registrationExistsFor()method 
public function registrationExistsFor(viewName:String):Boolean

Returns whether a view has been registered with a canonical name.

If two views are registered with the same canonical name, the second entry will overwrite the first. This method can be used to check whether a view has already been registered with a canonical name.

Parameters
viewName:String — canonical name for the view that the ViewHelper will check, eg "login"

Returns
Boolean — A Boolean that indicates if a view is already registered with that view name
unregister()method 
public function unregister(viewName:String):void

Unregisters a viewHelper using its canonical name.

Parameters
viewName:String — The canonical name for the view to be removed