-
Notifications
You must be signed in to change notification settings - Fork 16
13. Handler
Frank Hossfeld edited this page Dec 22, 2019
·
2 revisions
Nalu supports handlers. A handler behaves like a controller, but has no visual component. A Handler can only be triggered by an event. The following instances will be injected in a handler:
- context
- event bus
- router
Nalu will create handlers at application start. To trigger a handler, an event has to be fired.
To create a handler, you have to:
- extend AbstractHandler
- C: type of the context
By extending AbstractHandler you will have access to the allowing instances:
- C context: instance of the application context (Singleton)
- event bus: instance of the application wide event bus
- router: instance of the router
To tell Nalu, that this class is a handler, you have to annotate the class with Handler
. Nalu will automatically create an instance for each class annotated with @Handler
at application start.
A handler requires a
- a public, zero-argument constructor
- annotate the handler with
@Handler
Here is an example of a handler:
@Handler
public class MyHandler
extends AbstractHandler<MyApplicationContext> {
public MyHandler() {
}
@Override
public void bind() {
this.eventBus.addHandler(MyEvent.TYPE,
e -> {
// your code here
});
}
}