Interface ActionContext
- All Known Implementing Classes:
ActionContextBase
,MockActionContext
,ServletActionContext
,WebActionContext
An ActionContext represents a view of a commons-chain
Context
which encapsulates access to request and
session-scoped resources and services
-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addErrors
(ActionMessages errors) Append the given errors keys to an internal cache, creating the cache if one is not already present.void
addMessages
(ActionMessages messages) Append the given messages keys to an internal cache, creating the cache if one is not already present.Generate a new transaction token, to be used for enforcing a single request for a particular transaction.Get the action which has been identified to be executed as part of processing this request.Get the ActionConfig which contains the details for processing this request.Get the ActionForm instance which will carry any data submitted as part of this request.Return aMap
of Application scoped values.Indicate if the "cancel event" state is set for for this context,Retrieve error messages from an internal cache, creating an empty cache if one is not already present.Retrieve an exception which may have been caught by some code using this ActionContext, usually by an exception handler.Is the ActionForm for this context valid? This method does not actually perform form validation.Get the ForwardConfig which has been identified as the basis for view-processing.Get the include path which should be processed as part of processing this request.Return the user's currently selected Locale.Return the default message resources for the current module.Return the specified message resources for the current module.Retrieve messages from an internal cache, creating an empty cache if one is not already present.Get the ModuleConfig which is operative for the current request.Return aMap
of parameters submitted by the user as part of this request.Return aMap
of request scoped values.Return the Map representing the scope identified byscopeName
.Return aMap
of Session scoped values.boolean
Indicate whether a transaction token for this context is valid.boolean
isTokenValid
(boolean reset) Indicate whether a transaction token is stored in the "session" scope for this context, optionally clearing the token, so that the next check would return false.void
release()
Signal to the instance that it will not be used any more, so that any resources which should be cleaned up can be cleaned up.void
Clear any transactional token stored in the "session" scope for this context, so that the next check would return false.void
saveErrors
(ActionMessages errors) Save the given error messages to the internal cache, clearing any previous messages in the cache.void
saveMessages
(String scope, ActionMessages messages) Save the given messages to the internal cache, clearing any previous messages in the cache, but only for the specified scope.void
saveMessages
(ActionMessages messages) Save the given messages to the internal cache, clearing any previous messages in the cache.void
Save a new transaction token in the "session" scope for this context, creating new resources, if needed.void
Set the action which has been identified to be executed as part of processing this request.void
setActionConfig
(ActionConfig config) Set the ActionConfig class contains the details for processing this request.void
setActionForm
(ActionForm form) Set the ActionForm instance which will carry any data submitted as part of this request.void
setCancelled
(Boolean cancelled) Set the "cancel event" state for this context.void
Store an exception in this context for use by other handling code.void
setFormValid
(Boolean valid) Store the result of the validation of the Context's ActionForm.void
setForwardConfig
(ForwardConfig forward) Set the ForwardConfig which should be used as the basis of the view segment of the overall processing.void
setInclude
(String include) Set the include path which should be processed as part of processing this request.void
Set the user's currently selectedLocale
.void
setMessageResources
(MessageResources resources) Set the default message resources for the current module.void
setModuleConfig
(ModuleConfig config) Set the ModuleConfig which is operative for the current request.Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Field Details
-
APPLICATION_SCOPE
- See Also:
-
SESSION_SCOPE
- See Also:
-
REQUEST_SCOPE
- See Also:
-
-
Method Details
-
release
void release()Signal to the instance that it will not be used any more, so that any resources which should be cleaned up can be cleaned up. -
getApplicationScope
Return a
Map
of Application scoped values.This is implemented in analogy with the Application scope in the Servlet API, but it seems reasonable to expect that any Struts implementation will have an equivalent concept.
The ultimate meaning of "application scope" is an implementation detail left unspecified by Struts.
- Returns:
- A Map of "application scope" attributes.
-
getSessionScope
Return a
Map
of Session scoped values. A session is understood as a sequence of requests made by the same user.This is implemented in analogy with the Session scope in the Servlet API, but it seems reasonable to expect that any Struts implementation will have an equivalent concept.
The ultimate meaning of "session scope" is an implementation detail left unspecified by Struts.
- Returns:
- A Map of "session scope" attributes.
-
getRequestScope
Return a
Map
of request scoped values. A request is understood as the fundamental motivation for any particular instance of anActionContext
.This is implemented in analogy with the Request Context in the Servlet API, but it seems reasonable to expect that any Struts implementation will have an equivalent concept.
The ultimate meaning of "request scope" is an implementation detail left unspecified by Struts.
- Returns:
- a Map of "request scope" attributes.
-
getScope
Return the Map representing the scope identified byscopeName
. Implementations should support at minimum the names associated with the constantsAPPLICATION_SCOPE
,SESSION_SCOPE
, andREQUEST_SCOPE
, but are permitted to support others as well.- Parameters:
scopeName
- A token identifying a scope, including but not limited toAPPLICATION_SCOPE
,SESSION_SCOPE
,REQUEST_SCOPE
.- Returns:
- A Map of attributes for the specified scope.
-
getParameterMap
Return a
Map
of parameters submitted by the user as part of this request. The keys to this map will be request parameter names (of typeString
), and the values will beString[]
.This is implemented in analogy with the Request parameters of the Servlet API, but it seems reasonable to expect that any Struts implementation will have an equivalent concept.
- Returns:
- A map of the request parameter attributes
-
setAction
Set the action which has been identified to be executed as part of processing this request.
- Parameters:
action
-
-
getAction
Action getAction()Get the action which has been identified to be executed as part of processing this request.
- Returns:
- The action to be executed with this request
-
setActionForm
Set the ActionForm instance which will carry any data submitted as part of this request.
- Parameters:
form
- The ActionForm instance to use with this request
-
getActionForm
ActionForm getActionForm()Get the ActionForm instance which will carry any data submitted as part of this request.
- Returns:
- The ActionForm being used with this request
-
setActionConfig
Set the ActionConfig class contains the details for processing this request.
- Parameters:
config
- The ActionConfig class to use with this request
-
getActionConfig
ActionConfig getActionConfig()Get the ActionConfig which contains the details for processing this request.
- Returns:
- The ActionConfig class being used with this request
-
setForwardConfig
Set the ForwardConfig which should be used as the basis of the view segment of the overall processing. This is the primary method of "communication" with the "view" sub-chain.
- Parameters:
forward
- The ForwardConfig to use with this request
-
getForwardConfig
ForwardConfig getForwardConfig()Get the ForwardConfig which has been identified as the basis for view-processing.
- Returns:
- The ForwardConfig being used with this request
-
setInclude
Set the include path which should be processed as part of processing this request.
- Parameters:
include
- The include path to be used with this request
-
getInclude
String getInclude()Get the include path which should be processed as part of processing this request.
- Returns:
- The include path being used with this request
-
setModuleConfig
Set the ModuleConfig which is operative for the current request.
- Parameters:
config
- The ModuleConfig to be used with this request
-
getModuleConfig
ModuleConfig getModuleConfig()Get the ModuleConfig which is operative for the current request.
- Returns:
- The MooduleConfig being used with this request
-
getFormValid
Boolean getFormValid()Is the ActionForm for this context valid? This method does not actually perform form validation. It is simply a holder property where processes which perform validation can store the results of the validation for other processes' benefit.
- Returns:
Boolean.TRUE
if the form passed validation;Boolean.FALSE
if the form failed validation; null if the form has not yet been validated
-
setFormValid
Store the result of the validation of the Context's ActionForm.
- Parameters:
valid
- Whether the ActionForm for this request passes validation
-
getException
Exception getException()Retrieve an exception which may have been caught by some code using this ActionContext, usually by an exception handler.
- Returns:
- Any exception that may have been caught by this ActionContext
-
setException
Store an exception in this context for use by other handling code.
- Parameters:
e
- An exception to be stored for handling by another member
-
addMessages
Append the given messages keys to an internal cache, creating the cache if one is not already present.
- Parameters:
messages
- New ActionMessages to cache
-
addErrors
Append the given errors keys to an internal cache, creating the cache if one is not already present.
- Parameters:
errors
- New ActionMessages to cache as errors
-
getErrors
ActionMessages getErrors()Retrieve error messages from an internal cache, creating an empty cache if one is not already present.
- Returns:
- The ActionMessage cache for errors
-
getMessages
ActionMessages getMessages()Retrieve messages from an internal cache, creating an empty cache if one is not already present.
- Returns:
- The ActionMessage cache for errors
-
saveErrors
Save the given error messages to the internal cache, clearing any previous messages in the cache.
If the parameter is null or empty, the internal cache is removed.
- Parameters:
errors
- ActionMesssages to cache as errors
-
saveMessages
Save the given messages to the internal cache, clearing any previous messages in the cache.
If the parameter is null or empty, the internal cache is removed.
- Parameters:
messages
- ActionMesssages to cache
-
saveMessages
Save the given messages to the internal cache, clearing any previous messages in the cache, but only for the specified scope.
If the parameter is null or empty, the internal cache is removed.
- Parameters:
scope
- The scope for the internal cachemessages
- ActionMesssages to cache
-
generateToken
String generateToken()Generate a new transaction token, to be used for enforcing a single request for a particular transaction.
-
isTokenValid
boolean isTokenValid()Indicate whether a transaction token for this context is valid.
A typical implementation will place a transaction token in the session" scope Map and a matching value in the "parameter" Map. If the "session" token does not match the "parameter" attribute, or the session token is missing, then the transactional token is deemed invalid.
-
isTokenValid
boolean isTokenValid(boolean reset) Indicate whether a transaction token is stored in the "session" scope for this context, optionally clearing the token, so that the next check would return false.
- Parameters:
reset
- On true, clear the transactional token
-
resetToken
void resetToken()Clear any transactional token stored in the "session" scope for this context, so that the next check would return false.
-
saveToken
void saveToken()Save a new transaction token in the "session" scope for this context, creating new resources, if needed.
-
getCancelled
Boolean getCancelled()Indicate if the "cancel event" state is set for for this context,- See Also:
-
setCancelled
Set the "cancel event" state for this context.- Parameters:
cancelled
- On true, set the cancel event state to true. On false, set the cancel event state to false.- See Also:
-
getMessageResources
MessageResources getMessageResources()Return the default message resources for the current module.
-
setMessageResources
Set the default message resources for the current module.
-
getMessageResources
Return the specified message resources for the current module.
- Parameters:
key
- The key specified in the<message-resources>
element for the requested bundle
-
getLocale
Locale getLocale()Return the user's currently selected Locale.
-
setLocale
Set the user's currently selected
Locale
.- Parameters:
locale
- The user's selected Locale to be set, or null to select the server's default Locale
-