templates.plugins.spincast-variables-addon.spincast-variables-addon.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
{#==========================================
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 %}
Overview
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.
Installation
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,
IAppWebsocketContext.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...
}
// ...
}
The request context add-on
Quick example :
{% verbatim %}public void myHandler(IAppRequestContext context) {
context.variables().add("myVariable", "some value");
}{% endverbatim %}
Methods :
-
void add(String key, Object obj)
Adds a request scoped variable.
It is recommended that you prefixe the name of the
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)
Adds request scoped variables.
It is recommended that you prefixe the name of the
keys with the name of your class
(for example : this.getClass().getName()),
so they don't clash with other keys!
-
Map<String, Object> getAll()
Gets all the request scoped variables.
The map is immutable.
-
Object get(String key)
Gets the specified request scoped variable.
-
<T> T get(String key, Class<T> clazz)
Gets the specified request scoped variable as the
specified class.
-
<T> T get(String key, Key<T> typeKey)
Gets the specified request scoped variable as the
specified Key.
-
IJsonObject getAsJsonObject(String key)
Gets the specified request scoped variable as JsonObject.
-
String getAsString(String key)
Gets the specified request scoped variable as a String.
toString will be called on the Object.
-
void remove(String key)
Removes a request scoped variable.
Note: Spincast uses some request scoped variables for
internal purposes. Do not try to remove all
variables!
{% endblock %} 

Spincast Variables Addon