Any artifact or class that abides to the following conventions can be registered as an application listener, those conventions are:

There is a general, per application, script that can provide event handlers. If you want to take advantage of this feature you must define a script named Events.groovy inside griffon-app/conf. Lastly both Controller and Service instances are automatically registered as application event listeners. This is the only way to declare event listeners for Log4jConfigStart and BootstrapStart events.

You can also write a class named Events.java in src/main as an alternative to griffon-app/conf/Events.groovy, but not both!

These are some examples of event handlers:

File: griffon-app/conf/Events.groovy

onBootstrapEnd = { app ->
  println """Application configuration has finished loading.
MVC Groups will be initialized now."""
}

File: src/main/Events.java

import griffon.util.ApplicationHolder;

public class Events { public void onUncaughtExceptionThrown(Exception e) { ApplicationHolder.getApplication().shutdown(); } }

File: griffon-app/controller/MyController.groovy

class MyController {
  def onShutdownStart = { app ->
    println "${app.config.application.title} is shutting down"
  }
}

File: griffon-app/controller/MyController.groovy

class MyController {
  void mvcGroupInit(Map args) {
    app.addApplicationListener([
      Foo: {-> println 'got foo!' }
    ])
  }

def fooAction = { evt = null -> // do something app.event('Foo') } }

File: griffon-app/controller/MyController.groovy

class MyController {
  void mvcGroupInit(Map args) {
    app.addApplicationListener('Foo'){-> println 'got foo!' }
  }

def fooAction = { evt = null -> // do something app.event('Foo') } }

File: griffon-app/controller/MyController.java

import java.util.Map;
import griffon.util.RunnableWithArgs;
import org.codehaus.griffon.runtime.core.AbstractGriffonController;

public class MyController extends AbstractGriffonController { public void mvcGroupInit(Map<String, Object> params) { getApp().addApplicationListener("Foo", new RunnableWithArgs() { public void run(Object[] args) { System.out.println("got foo!"); } }); }

public void fooAction() { // do something getApp().event("Foo"); } }