You can create a Java service for your action extension to perform operations on objects in the vSphere environment. After the action operation completes, you must update accordingly the vSphere Web Client user interface.

Typically, an action requires you to make a change to the vSphere environment, such as changing the power state of a Virtual Machine, creating a new Host object, or deleting a vSphere object. You make changes to the vSphere environment by using a Java service in thevSphere Web Client service layer. A command class for an action extension must either import the Java service, or use a service proxy class. Methods in the Java service perform the actual operations in the vSphere environment.

A best practice is to create a Java service for your action extensions, and add that service to the vSphere Web Client service layer. You can then create a proxy class for the Java service, and use the service proxy in a command class. See Developing Extensions to the Service Layer.

For some actions, such as the Edit Chassis action in Example: Example Flex Command Class, you must obtain a reference to the target vSphere object that the user selected before performing the action. You can obtain a reference to the target vSphere object by using the ActionInvocationEvent that the Actions Framework generates when an action is triggered.

The ActionInvocationEvent contains an object of type ActionContext in the Actions Framework library. The ActionContext object contains an array named targetObjects, from which you can obtain references to all vSphere objects that the user has selected in the user interface. In Example: Example Flex Command Class, the method getIResourceReference shows an example of how to obtain a reference to the target object.

Your Flex command class must import the packages com.vmware.actionsfw.ActionContext and com.vmware.actionsfw.events.ActionInvocationEvent to use these vSphere Web Client SDK features.

When your Java service completes the action operation, you must update the vSphere Web Client with the results of that operation. You update the vSphere Web Client by dispatching a ModelChangeEvent in your command class.

To dispatch a ModelChangeEvent, your Flex command class must import the following classes: com.vmware.data.common.OperationType, com.vmware.data.common.ObjectChangeInfo, and com.vmware.data.common.events.ModelChangeEvent. You must also annotate your command class as follows.

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

You can use a callback method to ensure that your command class dispatches the necessary ModelChangeEvent. Your service proxy class can invoke the callback method in your command class when the action operation finishes. In Example: Example Flex Command Class, the command class passes references to the appropriate callback methods, onEditChassisComplete and onCreateChassisComplete, when it invokes the action operations in the service proxy. The callback methods then process the results of the action operation and dispatch the ModelChangeEvent as necessary.