In a Flex-based action extension, you use a command class to provide the code that performs the action operation in the vSphere environment when the user clicks your action.

When the user starts your action, the vSphere Web Client generates an ActionInvocationEvent using the ID you specified using the <uid> property in the ActionSpec object in your extension definition. The vSphere Web Client then instantiates the command class you specified in the <command> property. Your command class must contain a method annotated to handle the ActionInvocationEvent that is generated when the action is started. A single command class can contain handler methods for multiple actions, if those methods have the necessary annotations.

You annotate a method to handle an ActionInvocationEvent by using the [RequestHandler] metadata tag when you declare the method. In the [RequestHandler] tag, you must specify the <uid> property for the action to handle. To annotate a method to handle the Create Chassis command in Example: Flex-Based Action Extension Definition, you must include the following [RequestHandler] tag in your method declaration.

[RequestHandler("com.mySolution.myPlugin.createChassis")]

Your method must also accept the ActionInvocationEvent as a parameter.

The following example shows an example Flex command class. In the example, the ChassisCommand class contains a handler method for each of the actions defined in Example: Flex-Based Action Extension Definition.

package com.vmware.samples.chassisui {

import com.vmware.actionsfw.ActionContext;
import com.vmware.actionsfw.events.ActionInvocationEvent;
import com.vmware.core.model.IResourceReference;
import com.vmware.data.common.ObjectChangeInfo;
import com.vmware.data.common.OperationType;
import flash.events.EventDispatcher;
import mx.controls.Alert;

[Event(name="{com.vmware.data.common.events.ModelChangeEvent.MODEL_CHANGE}",
       type="com.vmware.data.common.events.ModelChangeEvent")]

public class ChassisCommand extends EventDispatcher {
   private var _proxy:ChassisServiceProxy = new ChassisServiceProxy();

   /** Create Chassis action handler **/
   [RequestHandler("com.mySolution.myPlugin.chassis.createChassis")]
   public function onCreateChassisActionInvocation(event:ActionInvocationEvent):void {
      _proxy.createChassis(onCreateChassisComplete);
   }

   /** Edit Chassis action handler **/
   [RequestHandler("com.mySolution.myPlugin.chassis.editChassis")]
   public function onEditChassisActionInvocation(event:ActionInvocationEvent):void {
      var chassisReference:IResourceReference = getIResourceReference(event);
      _proxy.editChassis(chassisReference, onEditChassisComplete, chassisReference);
   }

   private function onEditChassisComplete(event:MethodReturnEvent):void {
      if (event.error != null) {
         Alert.show(event.error.message);
         return;
      }
      var chassisReference:IResourceReference = event.callContext as IResourceReference;
      var mce:ModelChangeEvent = ModelChangeEvent.newSingleObjectChangeEvent(chassisReference,
                                                                             OperationType.CHANGE);
                                                                             dispatchEvent(mce);
      }

   private function onCreateChassisComplete(event:MethodReturnEvent):void {
      if (event.error != null) {
         Alert.show(event.error.message);
         return;
      }
      var chassisReference:IResourceReference = event.result as IResourceReference;
      var mce:ModelChangeEvent = ModelChangeEvent.newSingleObjectChangeEvent(chassisReference,
                                                                             OperationType.ADD);
                                                                             dispatchEvent(mce);
      }

   private function getIResourceReference(event:ActionInvocationEvent):IResourceReference {
      // actionContext.targetObjects is an array of objects on which the action is called
      // so actionContext.targetObjects[0] is the selected Chassis for this action.
      var actionContext:ActionContext = event.context;
      if (actionContext == null || (actionContext.targetObjects.length <= 0)
         || (!(actionContext.targetObjects[0] is IResourceReference))) {
         return null;
      }
      return (actionContext.targetObjects[0] as IResourceReference);
   }
}
}

In the example, the onCreateChassisActionInvocation and onEditChassisActionInvocation methods are annotated to handle the actions defined in the action set in Example: Flex-Based Action Extension Definition. The actual action operations are performed by an imported Java service. In the example, ChassisServiceProxy refers to a proxy class for a Java service that performs the action operations. See Performing Action Operations on the vSphere Environment.