{#========================================== Spincast Variables plugin ==========================================#} {% extends "../../layout.html" %} {% block sectionClasses %}plugins hasBreadCrumb plugins-spincast-variables-addon{% endblock %} {% block meta_title %}Plugins - Spincast Variables Addon{% endblock %} {% block meta_description %}Spincast Variables Addon plugin{% endblock %} {% block scripts %} {% endblock %} {% block body %}
This plugin provides an implementation for the
VariablesRequestContextAddon
Request Context add-on :
SpincastVariablesRequestContextAddon.
It allows a Route Handler to set
request scoped variables which will be available to other Route Handlers.
It is mounted as .variables() on the default Spincast Request Context.
.variables() add-on from a Route Handler
to get and set request scoped variables :
public void myHandler(AppRequestContext context) {
// Reads a request scoped variable
context.variables().get("someVariable");
// Adds a new request scoped variable
context.variables().add("newVariable", "some value");
//...
}
If you use the spincast-default artifact, this plugin is already installed so
you have nothing more to do!
If you start from scratch using the spincast-core artifact, you can use the
plugin by adding this artifact to your project:
<dependency>
<groupId>org.spincast</groupId>
<artifactId>spincast-plugins-variables-addon</artifactId>
<version>{{spincast.spincastCurrrentVersion}}</version>
</dependency>
You then install the plugin's Guice module, by passing it to the Guice.createInjector(...) method:
Injector guice = Guice.createInjector(
new SpincastCoreGuiceModule(args),
new SpincastVariablesPluginGuiceModule(AppRequestContext.class,
AppWebsocketContext.class)
// other modules...
);
... or by using the install(...) method from your custom Guice module:
public class AppModule extends SpincastCoreGuiceModule {
@Override
protected void configure() {
super.configure();
install(new SpincastVariablesPluginGuiceModule(getRequestContextType(),
getWebsocketContextType()));
// other modules...
}
// ...
}