The Script Manager is an Apache Rave bean that allows developers to register script blocks for inclusion in the bottom of the page. The bean is designed to manage the registration of scripts that should be rendered on every page (Global) and within the current context. Additionally, it tracks the requested position of the scripts relative to included libraries and out of the box Apache Rave scripts.
Getting the ScriptManager¶
The ScriptManager is a Spring bean defined by Rave and can be injected into any class via standard Spring autowiring mechanisms. If your component is not managed by Apache Rave's Spring Application Context, you can retrieve the bean from the Application Context manually.
Registering a Script¶
Scripts are registered to be rendered in a specific scope and relative location.
There potential values for the scope of a script's registration are defined in the org.apache.rave.web.renderer.RenderScope enumeration. Currently, there are two, GLOBAL and CURRENT_CONTEXT.
Scripts can be rendered at various points relative to Apache Rave default includes and out of the box scripts. The potential values are defined and document in the org.apache.rave.renderer.ScriptLocation enumeration.
The render context represents the environment under which the script is to be rendered. The context contains a set of key/value pairs that provide important context information to various components involved in the render process. The developers interacting with the script manager are responsible for passing the Render Context to the ScriptManager. Most often, the developer interacting with the ScriptManager will be doing so from within an Apache Rave render extension point, which will have a RenderContext passed to it. If this isn't the case, the developer will need to retrieve the RenderContext object from the current HttpServletRequest prior to calling the script manager.