Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This section describes the framework services that are available for views.

Table of Contents

ViewContext

The view server-side resources have access to a ViewContext object. The view context provides information about the current authenticated user, the view definition, the instance configuration properties, instance data and the view controller.

Code Block
  /**
   * The view context.
   */
  @Inject
  ViewContext context;

Instance Data

The view framework exposes a way to store key/value pair "instance data". This data is scoped to a given view instance and user. Instance data is meant to be used for information such as "user prefs" or other lightweight information that supports the experience of your view application. You can access the instance data get and put methods from the ViewContext object, which is available from your view server-side resources.

Info

Checkout the Favorite View for example usage of the instance data API.

https://github.com/apache/ambari/tree/trunk/ambari-views/examples/favorite-view

Code Block
/**
 * Context object available to the view components to provide access to
 * the view and instance attributes as well as run time information about
 * the current execution context.
 */
public interface ViewContext {

 /**
   * Save an instance data value for the given key.
   *
   * @param key    the key
   * @param value  the value
   *
   * @throws IllegalStateException if no instance is associated
   */
  public void putInstanceData(String key, String value);
  /**
   * Get the instance data value for the given key.
   *
   * @param key  the key
   *
   * @return the instance data value; null if no instance is associated
   */
  public String getInstanceData(String key);

}

 

Events

Events

Events are an important component of the views framework. Events allow the view to interact with the framework on lifecycle changes such as deploy (of the view) and create + destroy (of a view instance). As well, once a user has collection of views available, eventing allows the views to communicate with other views.

Framework Events
EventDescription
onDeploy()Called when a view is deployed.
onCreate()Called when a view instance is created.
onDestroy()Called when a view instance is destroy.

To register to receive framework events, in the view.xml, specify a <view-class>my.View.class</view-class> which is a class that implements the View interface.

Custom Events

TBD

ViewController viewContext.getViewController()

 

 TBD