public class ChainedAction extends AbstractAction
An action that makes it possible to chain together two, or more, actions into one. This is useful if you have an action that already fits the situation but needs one little thing added to it. For example, you could just use GenericTemplateAction, but you also want to send an email. You can chain together a SendEmailAction and the GenericTemplateAction with a ChainedAction. The ChainedAction is the action that receives the actual HTTP request, it then passes it on to the first action in the chain, if the action succeeded, it passes it on to the next action and so on. Note that in most cases only one of the actions in the chain should write anything in the response object.
You have other options as well to resolve the above use case. You could just extend GenericTemplateAction to make the action you need. Or, without extending the action, you could just pass in its template context a helper object that can do the other things you need to be done and then do them in the template.
To use this action, give the chained actions in an initialisation parameter named chain as a semicolon separated list. Each action in the chain must be named (using the name attribute in the module, like naming modules normally) and then the names used in the chain parameter. Usually you don't specify any action keys (the action or actions parameter) for the chained actions to prevent them from being used directly outside the chain. Although in some cases this could be desirable too.
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<AbstractAction> |
chain |
protected java.util.ArrayList<java.lang.String> |
chainNames |
actionParamKey, handledActions, httpHeaders, isDefaultAction, replacements, replacementsInitialized, servletModule
engine, initScript, persistentObjects, scriptManager, startScript, stopScript
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
ChainedAction() |
Modifier and Type | Method and Description |
---|---|
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
boolean |
handleAction(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
ModulesServlet.HttpMethod method,
java.lang.String action,
User user)
Handles this action.
|
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
void |
start(ModuleManager manager)
Starts the module.
|
void |
stop(ModuleManager manager)
Stops the module.
|
addHandledAction, doReplacements, handleRequest, isHandleAction, setActionParamKey, setHttpHeaders
getScriptEngine
isInitialized, isRunning, requireLogging, toString
protected java.util.ArrayList<AbstractAction> chain
protected java.util.ArrayList<java.lang.String> chainNames
public boolean handleAction(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, ModulesServlet.HttpMethod method, java.lang.String action, User user) throws javax.servlet.ServletException, java.io.IOException, ActionException
AbstractAction
handleAction
in class AbstractAction
req
- The HTTP Request.resp
- The HTTP response.method
- The HTTP method of the request.action
- The parsed action id.user
- The logged in user, or null if not applicable.javax.servlet.ServletException
java.io.IOException
ActionException
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
getDependencies
in class AbstractAction
manager
- The module manager handling this module.ModuleException
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
init
in class AbstractAction
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
public void start(ModuleManager manager) throws ModuleException
Module
start
in interface Module
start
in class AbstractAction
manager
- The module manager handling this module.ModuleException
public void stop(ModuleManager manager)
Module
stop
in interface Module
stop
in class AbstractAction
manager
- The module manager handling this module.Copyright 2004-2015 Wandora Team