{#========================================== Spincast Variables plugin ==========================================#} {% extends "../../layout.html" %} {% block sectionClasses %}plugins 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 %}
The Spincast Variables plugin provides a request context add-on :
"IVariablesRequestContextAddon". This add-on allows your route handlers to set
request scoped variables which will be available to other handlers.
It is mounted as .variables()
on the default Spincast request context.
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>{{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(IAppRequestContext.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()));
// other modules...
}
// ...
}
public void myHandler(IAppRequestContext context) {
context.variables().add("myVariable", "some value");
}{% endverbatim %}
void add(String key, Object obj)
key with the name of your class
(for example : this.getClass().getName()),
so it doesn't clash with other keys!
void add(Map<String, Object> variables)
keys with the name of your class
(for example : this.getClass().getName()),
so they don't clash with other keys!
Map<String, Object> getAll()
Object get(String key)
<T> T get(String key, Class<T> clazz)
<T> T get(String key, Key<T> typeKey)
Key.
IJsonObject getAsJsonObject(String key)
JsonObject.
String getAsString(String key)
toString will be called on the Object.
void remove(String key)