Class ActionContextBase
- All Implemented Interfaces:
Map<String,,Object> Context,ActionContext
- Direct Known Subclasses:
MockActionContext,WebActionContext
Provide an abstract but semi-complete implementation of ActionContext to serve as the base for concrete implementations.
The abstract
methods to implement are the accessors for the named states,
getApplicationScope, getRequestScope, and
getSessionScope.
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringProvide the default context attribute under which to store the ActionMessage cache for errors.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringProvide the default context attribute under which to store the ActionMessage cache.static final Stringstatic final Stringprotected TokenProcessorStore the TokenProcessor instance for this Context.static final StringProvide the default context attribute under which to store the token key.static final StringProvide the default context attribute under which to store the transaction token key.static final StringFields inherited from interface org.apache.struts.chain.contexts.ActionContext
APPLICATION_SCOPE, REQUEST_SCOPE, SESSION_SCOPE -
Constructor Summary
ConstructorsConstructorDescriptionInstantiate ActionContextBase, wrapping a default ContextBase instance.ActionContextBase(Context context) Instantiate ActionContextBase, wrapping the given Context. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddActionMessages(String key, ActionMessages messages) Add the given messages to a cache stored in this Context, under key.voidaddErrors(ActionMessages errors) Append the given errors keys to an internal cache, creating the cache if one is not already present.voidaddMessages(ActionMessages messages) Append the given messages keys to an internal cache, creating the cache if one is not already present.findOrCreateActionForm(String formName, String scopeName) Using thisActionContext's defaultModuleConfig, return an existingActionFormin the specified scope, or create a new one and add it to the specified scope.findOrCreateActionForm(String formName, String scopeName, ModuleConfig moduleConfig) In the context of the givenModuleConfigand thisActionContext, look for an existingActionFormin the specified scope.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 aMapof 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.Provide the currently configured commons-loggingLoginstance.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 aMapof request scoped values.Return the Map representing the scope identified byscopeName.Return aMapof Session scoped values.protected StringbooleanIndicate whether a transaction token for this context is valid.booleanisTokenValid(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.voidrelease()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.voidClear any transactional token stored in the "session" scope for this context, so that the next check would return false.voidsaveActionMessages(String scopeId, String key, ActionMessages messages) Save the givenmessagesinto the map identified by the givenscopeIdunder the givenkey.voidsaveActionMessages(String key, ActionMessages messages) Save the given ActionMessages into the request scope under the given key, clearing the attribute if the messages are empty or null.voidsaveErrors(ActionMessages errors) Save the given error messages to the internal cache, clearing any previous messages in the cache.voidsaveMessages(String scope, ActionMessages messages) Adapt a legacy form of SaveMessages to the ActionContext API by storing the ActoinMessages under the default scope.voidsaveMessages(ActionMessages messages) Save the given messages to the internal cache, clearing any previous messages in the cache.voidSave a new transaction token in the "session" scope for this context, creating new resources, if needed.voidSet the action which has been identified to be executed as part of processing this request.voidsetActionConfig(ActionConfig config) Set the ActionConfig class contains the details for processing this request.voidsetActionForm(ActionForm form) Set the ActionForm instance which will carry any data submitted as part of this request.voidsetCancelled(Boolean cancelled) Set the "cancel event" state for this context.voidStore an exception in this context for use by other handling code.voidsetFormValid(Boolean valid) Store the result of the validation of the Context's ActionForm.voidsetForwardConfig(ForwardConfig forward) Set the ForwardConfig which should be used as the basis of the view segment of the overall processing.voidsetInclude(String include) Set the include path which should be processed as part of processing this request.voidSet the user's currently selectedLocale.voidSet the slf4jLoggerinstance which should be used to LOG messages.voidsetMessageResources(MessageResources messageResources) Set the default message resources for the current module.voidsetModuleConfig(ModuleConfig config) Set the ModuleConfig which is operative for the current request.Methods inherited from class org.apache.struts.chain.contexts.ContextWrapper
clear, containsKey, containsValue, entrySet, get, getBaseContext, isEmpty, keySet, put, putAll, remove, size, valuesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.struts.chain.contexts.ActionContext
getParameterMapMethods 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
-
ACTION_KEY
- See Also:
-
ACTION_CONFIG_KEY
- See Also:
-
ACTION_FORM_KEY
- See Also:
-
FORWARD_CONFIG_KEY
- See Also:
-
MODULE_CONFIG_KEY
- See Also:
-
EXCEPTION_KEY
- See Also:
-
ERROR_ACTION_MESSAGES_KEY
Provide the default context attribute under which to store the ActionMessage cache for errors.- See Also:
-
MESSAGE_ACTION_MESSAGES_KEY
Provide the default context attribute under which to store the ActionMessage cache.- See Also:
-
MESSAGE_RESOURCES_KEY
- See Also:
-
INCLUDE_KEY
- See Also:
-
LOCALE_KEY
- See Also:
-
CANCEL_KEY
- See Also:
-
VALID_KEY
- See Also:
-
TRANSACTION_TOKEN_KEY
Provide the default context attribute under which to store the transaction token key.- See Also:
-
TOKEN_KEY
Provide the default context attribute under which to store the token key.- See Also:
-
token
Store the TokenProcessor instance for this Context.
-
-
Constructor Details
-
ActionContextBase
Instantiate ActionContextBase, wrapping the given Context.- Parameters:
context- Context to wrap
-
ActionContextBase
public ActionContextBase()Instantiate ActionContextBase, wrapping a default ContextBase instance.
-
-
Method Details
-
release
public void release()Description copied from interface:ActionContextSignal to the instance that it will not be used any more, so that any resources which should be cleaned up can be cleaned up.- Specified by:
releasein interfaceActionContext
-
getApplicationScope
Description copied from interface:ActionContextReturn a
Mapof 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.
- Specified by:
getApplicationScopein interfaceActionContext- Returns:
- A Map of "application scope" attributes.
-
getRequestScope
Description copied from interface:ActionContextReturn a
Mapof 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.
- Specified by:
getRequestScopein interfaceActionContext- Returns:
- a Map of "request scope" attributes.
-
getSessionScope
Description copied from interface:ActionContextReturn a
Mapof 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.
- Specified by:
getSessionScopein interfaceActionContext- Returns:
- A Map of "session scope" attributes.
-
getScope
Description copied from interface:ActionContextReturn 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.- Specified by:
getScopein interfaceActionContext- 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.
-
setAction
Description copied from interface:ActionContextSet the action which has been identified to be executed as part of processing this request.
- Specified by:
setActionin interfaceActionContext- Parameters:
action-
-
getAction
Description copied from interface:ActionContextGet the action which has been identified to be executed as part of processing this request.
- Specified by:
getActionin interfaceActionContext- Returns:
- The action to be executed with this request
-
setActionForm
Description copied from interface:ActionContextSet the ActionForm instance which will carry any data submitted as part of this request.
- Specified by:
setActionFormin interfaceActionContext- Parameters:
form- The ActionForm instance to use with this request
-
getActionForm
Description copied from interface:ActionContextGet the ActionForm instance which will carry any data submitted as part of this request.
- Specified by:
getActionFormin interfaceActionContext- Returns:
- The ActionForm being used with this request
-
setActionConfig
Description copied from interface:ActionContextSet the ActionConfig class contains the details for processing this request.
- Specified by:
setActionConfigin interfaceActionContext- Parameters:
config- The ActionConfig class to use with this request
-
getActionConfig
Description copied from interface:ActionContextGet the ActionConfig which contains the details for processing this request.
- Specified by:
getActionConfigin interfaceActionContext- Returns:
- The ActionConfig class being used with this request
-
setForwardConfig
Description copied from interface:ActionContextSet 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.
- Specified by:
setForwardConfigin interfaceActionContext- Parameters:
forward- The ForwardConfig to use with this request
-
getForwardConfig
Description copied from interface:ActionContextGet the ForwardConfig which has been identified as the basis for view-processing.
- Specified by:
getForwardConfigin interfaceActionContext- Returns:
- The ForwardConfig being used with this request
-
setInclude
Description copied from interface:ActionContextSet the include path which should be processed as part of processing this request.
- Specified by:
setIncludein interfaceActionContext- Parameters:
include- The include path to be used with this request
-
getInclude
Description copied from interface:ActionContextGet the include path which should be processed as part of processing this request.
- Specified by:
getIncludein interfaceActionContext- Returns:
- The include path being used with this request
-
getFormValid
Description copied from interface:ActionContextIs 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.
- Specified by:
getFormValidin interfaceActionContext- Returns:
Boolean.TRUEif the form passed validation;Boolean.FALSEif the form failed validation; null if the form has not yet been validated
-
setFormValid
Description copied from interface:ActionContextStore the result of the validation of the Context's ActionForm.
- Specified by:
setFormValidin interfaceActionContext- Parameters:
valid- Whether the ActionForm for this request passes validation
-
getModuleConfig
Description copied from interface:ActionContextGet the ModuleConfig which is operative for the current request.
- Specified by:
getModuleConfigin interfaceActionContext- Returns:
- The MooduleConfig being used with this request
-
setModuleConfig
Description copied from interface:ActionContextSet the ModuleConfig which is operative for the current request.
- Specified by:
setModuleConfigin interfaceActionContext- Parameters:
config- The ModuleConfig to be used with this request
-
getException
Description copied from interface:ActionContextRetrieve an exception which may have been caught by some code using this ActionContext, usually by an exception handler.
- Specified by:
getExceptionin interfaceActionContext- Returns:
- Any exception that may have been caught by this ActionContext
-
setException
Description copied from interface:ActionContextStore an exception in this context for use by other handling code.
- Specified by:
setExceptionin interfaceActionContext- Parameters:
e- An exception to be stored for handling by another member
-
addMessages
Description copied from interface:ActionContextAppend the given messages keys to an internal cache, creating the cache if one is not already present.
- Specified by:
addMessagesin interfaceActionContext- Parameters:
messages- New ActionMessages to cache
-
addErrors
Description copied from interface:ActionContextAppend the given errors keys to an internal cache, creating the cache if one is not already present.
- Specified by:
addErrorsin interfaceActionContext- Parameters:
errors- New ActionMessages to cache as errors
-
getErrors
Description copied from interface:ActionContextRetrieve error messages from an internal cache, creating an empty cache if one is not already present.
- Specified by:
getErrorsin interfaceActionContext- Returns:
- The ActionMessage cache for errors
-
getMessages
Description copied from interface:ActionContextRetrieve messages from an internal cache, creating an empty cache if one is not already present.
- Specified by:
getMessagesin interfaceActionContext- Returns:
- The ActionMessage cache for errors
-
saveErrors
Description copied from interface:ActionContextSave 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.
- Specified by:
saveErrorsin interfaceActionContext- Parameters:
errors- ActionMesssages to cache as errors
-
saveMessages
Description copied from interface:ActionContextSave 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.
- Specified by:
saveMessagesin interfaceActionContext- Parameters:
messages- ActionMesssages to cache
-
addActionMessages
Add the given messages to a cache stored in this Context, under key.
- Parameters:
key- The attribute name for the message cachemessages- The ActionMessages to add
-
saveActionMessages
Save the given ActionMessages into the request scope under the given key, clearing the attribute if the messages are empty or null.
- Parameters:
key- The attribute name for the message cachemessages- The ActionMessages to add
-
saveActionMessages
Save the given
messagesinto the map identified by the givenscopeIdunder the givenkey.- Parameters:
scopeId-key-messages-
-
saveMessages
Adapt a legacy form of SaveMessages to the ActionContext API by storing the ActoinMessages under the default scope.
- Specified by:
saveMessagesin interfaceActionContext- Parameters:
scope- The scope for the internal cachemessages- ActionMesssages to cache
-
saveToken
public void saveToken()Description copied from interface:ActionContextSave a new transaction token in the "session" scope for this context, creating new resources, if needed.
- Specified by:
saveTokenin interfaceActionContext
-
generateToken
Description copied from interface:ActionContextGenerate a new transaction token, to be used for enforcing a single request for a particular transaction.
- Specified by:
generateTokenin interfaceActionContext
-
getTokenGeneratorId
-
isTokenValid
public boolean isTokenValid()Description copied from interface:ActionContextIndicate 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.
- Specified by:
isTokenValidin interfaceActionContext
-
isTokenValid
public boolean isTokenValid(boolean reset) Description copied from interface:ActionContextIndicate 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.
- Specified by:
isTokenValidin interfaceActionContext- Parameters:
reset- On true, clear the transactional token
-
resetToken
public void resetToken()Description copied from interface:ActionContextClear any transactional token stored in the "session" scope for this context, so that the next check would return false.
- Specified by:
resetTokenin interfaceActionContext
-
getCancelled
Description copied from interface:ActionContextIndicate if the "cancel event" state is set for for this context,- Specified by:
getCancelledin interfaceActionContext- See Also:
-
setCancelled
Description copied from interface:ActionContextSet the "cancel event" state for this context.- Specified by:
setCancelledin interfaceActionContext- Parameters:
cancelled- On true, set the cancel event state to true. On false, set the cancel event state to false.- See Also:
-
setMessageResources
Description copied from interface:ActionContextSet the default message resources for the current module.
- Specified by:
setMessageResourcesin interfaceActionContext
-
getMessageResources
Description copied from interface:ActionContextReturn the default message resources for the current module.
- Specified by:
getMessageResourcesin interfaceActionContext
-
getMessageResources
Description copied from interface:ActionContextReturn the specified message resources for the current module.
- Specified by:
getMessageResourcesin interfaceActionContext- Parameters:
key- The key specified in the<message-resources>element for the requested bundle
-
setLocale
Description copied from interface:ActionContextSet the user's currently selected
Locale.- Specified by:
setLocalein interfaceActionContext- Parameters:
locale- The user's selected Locale to be set, or null to select the server's default Locale
-
getLocale
Description copied from interface:ActionContextReturn the user's currently selected Locale.
- Specified by:
getLocalein interfaceActionContext
-
getLogger
Provide the currently configured commons-logging
Loginstance.- Returns:
- Logger instance for this context
-
setLogger
Set the slf4jLoggerinstance which should be used to LOG messages. This is initialized at instantiation time but may be overridden. Be advised not to set the value to null, asActionContextBaseuses the logger for some of its own operations.- Parameters:
logger- instance for this context
-
findOrCreateActionForm
public ActionForm findOrCreateActionForm(String formName, String scopeName) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException Using thisActionContext's defaultModuleConfig, return an existingActionFormin the specified scope, or create a new one and add it to the specified scope.- Parameters:
formName- The name attribute of our ActionFormscopeName- The scope identifier (request, session)- Returns:
- The ActionForm for this request
- Throws:
InstantiationException- If object cannot be createdIllegalAccessException- If object cannot be createdIllegalArgumentException- If form config is missing from module or scopeName is invalidInvocationTargetException- if the underlying constructor throws an exceptionNoSuchMethodException- if a matching method is not foundSecurityException- if there is a security-exceptionClassNotFoundException- if the specified class cannot be loaded- See Also:
-
findOrCreateActionForm
public ActionForm findOrCreateActionForm(String formName, String scopeName, ModuleConfig moduleConfig) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException In the context of the givenModuleConfigand thisActionContext, look for an existingActionFormin the specified scope. If one is found, return it; otherwise, create a new instance, add it to that scope, and then return it.- Parameters:
formName- The name attribute of our ActionFormscopeName- The scope identier (request, session)- Returns:
- The ActionForm for this request
- Throws:
InstantiationException- If object cannot be createdIllegalAccessException- If object cannot be createdIllegalArgumentException- If form config is missing from module or scopeName is invalidInvocationTargetException- if the underlying constructor throws an exceptionNoSuchMethodException- if a matching method is not foundSecurityException- if there is a security-exceptionClassNotFoundException- if the specified class cannot be loaded
-