Application wide context - MTDdk/jawn GitHub Wiki

Sometimes you need to have some state shared for the lifetime of the application, and this is done by using the AppContext in the app.config.AppBootstrap:

public class AppBootstrap extends Bootstrap {
    public void init(AppContext context) {
        context.set("framework_name", "java-web-planet");
    }
}

Everything in the AppContext can then be retrieved from every controller:

public class IndexController extends ApplicationController {
    public void index(){
         view("framework_name", appContext().get("app_name"));
    }
}

The AppContext is mostly just a Map, but it has some extra methods. Most notable:

/*
 * Sets the encoding of every generated content
 */
context.setEncoding("UTF-8"); // this is the standard encoding

/*
 * Enables the application to be language sensitive.
 * 
 * First element is the default language, which is used,
 * when no language is defined
 */
context.setSupportedLanguages("en", "de", "fr");