...
Events are an important component of the views framework. Events allow the view to interact with the framework on lifecycle changes (i.e. "framework events"). such as deploy (of the view) and create + destroy (of a view instance), create and destroy. As well, once a user has collection of views available, eventing allows the views to communicate with other views (i.e. "view events").
Framework Events
Event | Description |
---|---|
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>this.is.my.view-clazz</view-class>
which is a class that implements the View interface.
Custom Events
TBD
View Events
From the view context, you can obtain the ViewController object that allows you to register listeners for view events and to fire events for other listeners.
Code Block |
---|
ViewController viewContext.getViewController(); |
Registering Listeners
A view can register to listen for view events from other views by view name, or by view name + version. When an event is fired from the source view, all registered listeners will receive the event.
Firing Events
- Create an event.
http://github.com/apache/ambari/blob/trunk/ambari-views/src/main/java/org/apache/ambari/view/events/Event.java - Fire the event.
controller.fireEvent(event)
Receiving Events
The framework will notify all registered listeners.
listener.notify(event)
ViewController viewContext.getViewController()