|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.support.ApplicationObjectSupport org.springframework.web.context.support.WebApplicationObjectSupport org.springframework.web.servlet.support.WebContentGenerator org.springframework.web.servlet.mvc.AbstractController org.szegedi.spring.web.jsflow.FlowController
public class FlowController
A Spring MVC Controller
that uses
Rhino ECMAScript engine to implement flows. A controller requires a
FlowStateStorage
, a ScriptStorage
, and a
ScriptSelectionStrategy
to operate properly. It can be either wired
(manually or autowired) by a bean factory to them, or it can discover them
by itself in the application context. As a last resort, if it can not find
these objects, it will create its own instances of them (it will use a
HttpSessionFlowStateStorage
and a
UrlScriptSelectionStrategy
). A single instance of controller can
encapsulate a single webflow represented by a single script, or it can
handle several flows represented by several scripts, depending on the script
selection strategy used. The operation of the controller can be cusomized by
installing various interceptors into it.
Field Summary | |
---|---|
static java.lang.String |
HOST_PROPERTY
|
static java.lang.String |
SCRIPT_DIR_PROPERTY
|
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator |
---|
METHOD_GET, METHOD_HEAD, METHOD_POST |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
logger |
Constructor Summary | |
---|---|
FlowController()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
static ScriptStorage |
createDefaultScriptStorage(org.springframework.context.ApplicationContext ctx)
|
protected org.springframework.web.servlet.ModelAndView |
handleRequestInternal(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
First, the controller determines if there is a request parameter named "stateId" and if it contains a valid state ID. |
void |
setContextFactory(org.mozilla.javascript.ContextFactory contextFactory)
Sets the Rhino context factory to use. |
void |
setFlowExecutionInterceptor(FlowExecutionInterceptor flowExecutionInterceptor)
Sets the flow execution interceptor used to custom initialize an instance of a flow before it first executes, as well as perform any cleanup after an instance of a flow terminates. |
void |
setFlowStateStorage(FlowStateStorage flowStateStorage)
Sets the flow state storage used to store flow states between a HTTP response and the next HTTP request. |
void |
setResourcePath(java.lang.String resourcePath)
Deprecated. Use setScriptSelectionStrategy(ScriptSelectionStrategy) with
a UrlScriptSelectionStrategy instead |
void |
setScriptSelectionStrategy(ScriptSelectionStrategy scriptSelector)
Sets the script selector used to select scripts for initial HTTP requests. |
void |
setScriptStorage(ScriptStorage scriptStorage)
Sets the script storage used to load scripts. |
void |
setStateExecutionInterceptor(StateExecutionInterceptor stateExecutionInterceptor)
Sets the flow state interceptor used to provide "around" advice around each state execution of each flow. |
void |
setUsePathInfo(boolean usePathInfo)
Deprecated. Use setScriptSelectionStrategy(ScriptSelectionStrategy) with
a UrlScriptSelectionStrategy instead |
void |
setUseServletPath(boolean useServletPath)
Deprecated. Use setScriptSelectionStrategy(ScriptSelectionStrategy) with
a UrlScriptSelectionStrategy instead |
Methods inherited from class org.springframework.web.servlet.mvc.AbstractController |
---|
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession |
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator |
---|
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseExpiresHeader |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
---|
getServletContext, getTempDir, getWebApplicationContext, isContextRequired, setServletContext |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String HOST_PROPERTY
public static final java.lang.String SCRIPT_DIR_PROPERTY
Constructor Detail |
---|
public FlowController()
Method Detail |
---|
public void setFlowStateStorage(FlowStateStorage flowStateStorage)
HttpSessionFlowStateStorage
.
flowStateStorage
- public void setScriptStorage(ScriptStorage scriptStorage)
scriptStorage
- public void setScriptSelectionStrategy(ScriptSelectionStrategy scriptSelector)
UrlScriptSelectionStrategy
with
UrlScriptSelectionStrategy.setUseServletPath(boolean)
set to
true will be used.
scriptSelector
- public void setContextFactory(org.mozilla.javascript.ContextFactory contextFactory)
OpenContextInViewInterceptor
(otherwise the interceptor's is used). If not set, the global context
factory returned by ContextFactory.getGlobal()
will be used.
contextFactory
- public void setResourcePath(java.lang.String resourcePath)
setScriptSelectionStrategy(ScriptSelectionStrategy)
with
a UrlScriptSelectionStrategy
instead
public void setUsePathInfo(boolean usePathInfo)
setScriptSelectionStrategy(ScriptSelectionStrategy)
with
a UrlScriptSelectionStrategy
instead
public void setUseServletPath(boolean useServletPath)
setScriptSelectionStrategy(ScriptSelectionStrategy)
with
a UrlScriptSelectionStrategy
instead
public void setFlowExecutionInterceptor(FlowExecutionInterceptor flowExecutionInterceptor)
flowExecutionInterceptor
- public void setStateExecutionInterceptor(StateExecutionInterceptor stateExecutionInterceptor)
stateExecutionInterceptor
- the state execution interceptor to use.public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
public static ScriptStorage createDefaultScriptStorage(org.springframework.context.ApplicationContext ctx) throws java.lang.Exception
java.lang.Exception
protected org.springframework.web.servlet.ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
RequestDispatcher.include(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
call, the controller will correctly use
the request attributes javax.servlet.include.servlet_path and
javax.servlet.include.path_info instead of the request's proper
servlet path and path info.
All flowscripts have access to the following built-in objects:
Name | Object |
---|---|
request | the HttpServletRequest object |
response | the HttpServletResponse object |
servletContext | the ServletContext object |
applicationContext | the ApplicationContext object |
They also have access to following built-in functions:
Function | Purpose |
---|---|
include(path) | includes a script referenced with the specified path as if it was executed at the point of inclusion. You can use it to conveniently include reusable function modules. For absolute pathnames (relative to the root of the namespace of the resource loader configured in the associated script storage), start the path with /. Otherwise, the paths are interpreted as relative to the including script. In relative paths, you can use any number of ../ components at the start of the path to refer to parent directories. Relative paths were introduced in 1.1.1 release. For compatibility with older releases that only supported absolute paths, if a relative path can not be resolved to an existing script, the system will also try to resolve it as an old-format absolute path. |
respond(viewName, model) | respond to the actual HTTP request with the specified view name and the specified model. The view is resolved using the Spring's view resolution mechanism. The model can be any Rhino Scriptable instance (including this to pass all script variables to the model), the controller will take care of fitting a Map interface to it to conform to Spring model requirements. The actual sending of the response will not happen until the script either terminates, or calls the wait() function. Another invocation of the function before the actual sending of the reponse happens will overwrite a previous one. The script can pass null for the view name to indicate it handled the response completely on its own and no view needs to be invoked. |
wait() | send the response and then waits for the next HTTP request. The function will return when another HTTP request for that flow is made. Upon returning from this function, the variables request and response will have new values, therefore scripts should not store references to them across waits. When wait() is invoked, an additional variable named "stateId" is placed into the model. The view should pass this id to the client, who should specify it in a request parameter also named "stateId" in the next HTTP request to continue the flow. |
respondAndWait(viewName, model) | conveniently combines the respond() and wait() functions into a single function. |
isGoingToWait() | returns true if the script
is about to go waiting as a result of a wait() call. All open
finally blocks are executed in Rhino whenever wait() is
called. This function can be used in finally blocks to distinguish
between control flow exiting the block for the last time (really
"finally") and control flow exiting the block because of wait. I.e. the
typical use is:
try { ... respondAndWait("confirm.html", data); ... } finally { if(!isGoingToWait()) { // perform the "real finally" cleanup here ... } } |
handleRequestInternal
in class org.springframework.web.servlet.mvc.AbstractController
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |