The view class and the mediator class are associated using metadata tags. The MXML view class uses the [DefaultMediator] tag to specify the associated mediator class.
Example: Sample Frinje View Class shows a sample MXML view class with an associated mediator. The name of the associated mediator class in the example is
com.acme.myPlugin.views.MyPluginMediator.
The ActionScript mediator class uses the [View] tag to specify the associated view class.
Example: Sample Frinje Mediator Class shows a sample ActionScript mediator class with functions to set and retrieve the associated view. The name of the associated view class in the example is
MyPluginView.
When your mediator class implements the IContextObjectHolder interface, you must provide
get and
set methods for the
contextObject property. You do not need to set the
contextObject property directly. The Frinje framework calls the mediator class
set contextObject() method when the view becomes active. The currently selected vSphere object is passed to
set contextObject() as the parameter
value.
A best practice is to place your data view’s initial data requests and other initialization code in the set contextObject() method. That way, you can initialize the view when the framework passes the currently selected object as the view becomes active.
Example 5-3, on page 44, shows an example mediator class. The example mediator class contains the logic for a data view for a custom object type called Chassis. The example mediator implements the
IContextObjectHolder interface, and uses
set contextObject() to obtain the currently selected Chassis object.
In the example, the framework invokes the set contextObject() method, which in turn sends an initial data request, or clears the interface if no object is selected.
You use the [DefaultMediator] tag to declare the mediator class associated with a particular view component. You typically use this tag in your view MXML class, to specify the ActionScript class that contains the UI logic. The
[DefaultMediator] tag has one argument, which must be the fully qualified class name for the mediator class.
To use the [DefaultMediator] tag in an MXML class, you must enclose the tag in
<mx:Metadata> elements.
Example: Example [DefaultMediator] Metadata Tag in MXML view shows an example
[DefaultMediator] tag.
In the example, the [DefaultMediator] tag declares the
ChassisSummaryViewMediator class as the mediator class for the view described in MXML.
You use the [Event] tag to define any events that your class generates. You must insert the
[Event] tag before the ActionScript class definition for any class that dispatches events.
The [Event] tag is a native Flex metadata tag that contains the arguments
name and
type. You use the
name argument to specify the event property that your class can dispatch, and the
type argument to specify the data type for the event object.
In the vSphere Web Client SDK, you typically use the [Event] tag to specify events from the SDK’s Data Access Manager library. Your classes can dispatch these events to request data from the vSphere environment. See
Using the Data Access Manager Library.
Example: Example [Event] Metadata Tag in Mediator Class shows an example mediator class annotated to dispatch a Data Access Manager event. The event class is included in the
com.vmware.data.query library in the vSphere Web Client SDK.
In the example, the name attribute in the
[Event] tag has the value
{com.vmware.data.query.events.DataByModelRequest.Request_ID}. The
REQUEST_ID corresponds to a specific event identifier defined in the
DataByModelRequest class, rather than a hard-coded event name.
You use the [Model] tag to annotate a data model class. Data model classes are used to specify information being retrieved through the vSphere Web Client SDK Data Access Manager library. See
Using the Data Access Manager Library.
You use the [RequestHandler] tag to annotate a method to handle a particular action in the vSphere Web Client. Typically, you create a command class for your action and annotate a method in that command class with the
[RequestHandler] tag.
The [RequestHandler] tag has one parameter, which is the UID for the action that the method handles. The action UID in the
[RequestHandler] tag must match the action UID that you specified in the action’s extension definition. See
Chapter 7, “Creating Action Extensions,” on page 65.
You use the [ResponseHandler] tag to annotate a method to handle a specific type of event. Methods annotated with [ResponseHandler] handle data response events generated by the Data Access Manager library.
The method you annotate with the [ResponseHandler] tag listens for specific, named events that are dispatched from its parent component class. When writing a UI component class, such as a mediator, you typically annotate the class with the
[Event] tag to specify the events named events that the class can generate. You can then annotate specific methods within that class with
[ResponseHandler] to handle each event.
The [ResponseHandler] tag has a single argument, which you use to specify the event name that the method expects.
The method you annotate with [ResponseHandler] must accept the parameters
request and
result, representing the type of data request and the result of the data request, respectively. The
request type must match that of the dispatched event. The method you annotate with
[ResponseHandler] can also accept the optional parameters
error and
resultInfo.
Example: Example [ResponseHandler] Metadata Tag in Event Handler Method shows an example method annotated to handle a Data Access Manager data response event. The event class is included in the
com.vmware.data.query library in the vSphere Web Client SDK.
In the example, the onData function is annotated to receive the event
com.vmware.data.query.events.DataByModelRequest.Response_ID. The event must be generated from the
onData function’s parent class, and the parent class must be annotated with an
[Event] tag that specifies that the class dispatches the
com.vmware.data.query.events.DataByModelRequest.Response_ID event.
You use the [EventHandler] tag to annotate a method to handle a general, application-wide notification event. An example of such an event is the
DataRefreshInvocationEvent that is generated when the user clicks the global refresh button in the vSphere Web Client UI.
The [EventHandler] tag has one argument, which specifies the name of the event for which the method is listening.
The method you annotate with [EventHandler] must accept an
event parameter. The
event parameter contains the generated event.
You can annotate a method with [EventHandler] to handle data responses from Data Access Manager. However, a method annotated with [ResponseHandler] is more suited to handling data requests. The Frinje framework extracts the request type and result data automatically for
[ResponseHandler] methods.
Example: Example [EventHandler] Metadata Tag in Event Handler Method shows an example method annotated to handle the global
DataRefreshInvocationEvent.
You use the [View] tag to inject a view component object into the view’s associated mediator class. When you use the
[View] tag, you can reference the view component with a generic view variable, and the Frinje framework will associate the mediator with the specific view at creation time. The associated view must be annotated with the
[DefaultMediator] tag for the framework to make the association. See
DefaultMediator.
Example 5-9, on page 49, shows an example of a mediator class that declares a generic variable for the view class, and uses the
[View] tag to inject the view component in the mediator
get and
set methods for the view.