Your classes and methods make use of the Frinje framework by including metadata annotations with the class or method declaration.

When you construct your classes, you can use the following metadata annotations: [DefaultMediator], [Event], [Model], [RequestHandler], [ResponseHandler], [EventHandler] and [View]. Each annotation has certain required attributes you must include.

Note

String arguments in metadata annotations are not validated at compile time. If you encounter errors or your extensions do not function correctly, review your metadata annotations. In addition, it is a best practice to use the fully qualified class name for any class arguments included in your metadata annotations.

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.

[DefaultMediator("<fully_qualified_class_name>")]

To use the [DefaultMediator] tag in an MXML class, you must enclose the tag in <mx:Metadata> elements.

The following example [DefaultMediator] tag declares the ChassisSummaryViewMediator class as the mediator class for the view described in MXML.

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Metadata>
        [DefaultMediator("com.vmware.samples.chassisui.views.ChassisSummaryViewMediator")]
    <mx:Metadata>
    ...

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 name of the event that your class can dispatch, and the type argument to specify the data type for the event object.

[Event(name="<event_name>", type="<event_type>")]

In the vSphere Web Client SDK, you typically use the [Event] tag to specify events from the Data Access Manager library. Your classes can dispatch these events to request data from the vSphere environment. See Using the Data Access Manager Library

The following example mediator class is 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.

// Declares the data request event sent from this UI class.
[Event(name="{com.vmware.data.query.events.DataByModelRequest.REQUEST_ID}",
       type="com.vmware.data.query.events.DataByModelRequest")]

public class ChassisSummaryViewMediator extends EventDispatcher implements IContextObjectHolder {
    ...
 
  private function requestData():void {
  // Dispatch an event to fetch the _contextObject data from the server along the specified model.
    dispatchEvent(DataByModelRequest.newInstance(_contextObject, ChassisSummaryDetails));
  }
    ...

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 Creating Action Extensions.

[RequestHandler("<action_uid>")]

You use the [ResponseHandler] tag to annotate a method to handle a specific type of event generated by the Data Access Manager library in response to a data request.

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.

[ResponseHandler(name="<response_event_name>")]

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.

The following example method is 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. The onData function is annotated to receive the event com.vmware.data.query.events.DataByModelRequest.Response_ID. The event must be generated from the parent class of the onData function. 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.

[ResponseHandler(name="{com.vmware.data.query.events.DataByModelRequest.RESPONSE_ID}")]
public function onData(request:DataByModelRequest, result:ChassisSummaryDetails):void {
    _view.chassisDetails = result;
}

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.

[EventHandler(name="event_name")]

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 the 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.

The following example method is annotated to handle the global DataRefreshInvocationEvent.

[EventHandler(name="{com.vmware.core.events.DataRefreshInvocationEvent.EVENT_ID}")]
public function onGlobalRefreshRequest(event:DataRefreshInvocationEvent):void {
    requestData();
}

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.

The following example mediator class 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.

/**
* The mediator for the ChassisSummaryView view.
*/
public class ChassisSummaryViewMediator extends EventDispatcher implements IContextObjectHolder {
 
    private var _view:ChassisSummaryView;
 
    [View]
    public function get view():ChassisSummaryView {
        return _view;
    }
 
    public function set view(value:ChassisSummaryView):void {
        _view = value;
    }
            ...