Package org.apache.struts2
Class ActionContext
java.lang.Object
org.apache.struts2.ActionContext
- All Implemented Interfaces:
Serializable
The ActionContext is the context in which an Action
is executed. Each context is basically a
container of objects an action needs for execution like the session, parameters, locale, etc.
The ActionContext is thread local which means that values stored in the ActionContext are
unique per thread. See the ThreadLocal
class for more information. The benefit of
this is you don't need to worry about a user specific action context, you just get it:
ActionContext context = ActionContext.getContext();
Finally, because of the thread local usage you don't need to worry about making your actions thread safe.
- Author:
- Patrick Lightbody, Bill Lynch (docs)
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ActionContext
(Map<String, Object> context) Creates a new ActionContext initialized with another context. -
Method Summary
Modifier and TypeMethodDescriptionbind()
Binds this context with the current threadstatic ActionContext
bind
(ActionContext actionContext) Binds the provided context with the current threadstatic void
clear()
Wipes out current ActionContext, use wisely!static boolean
containsValueStack
(Map<String, Object> context) final boolean
Returns a value that is stored in the current ActionContext by doing a lookup using the value's key.Gets the action invocation (the execution state).Gets ActionMapping associated with current actionGets the name of the current Action.Returns a Map of the ServletContext when in a servlet environment or a generic application level Map otherwise.Sets the container for this requeststatic ActionContext
Returns the ActionContext specific to the current thread.Gets the context map.Gets the map of conversion errors which occurred when executing the action.<T> T
getInstance
(Class<T> type) Gets the Locale of the current action.jakarta.servlet.jsp.PageContext
Gets PageContext associated with current actionReturns a Map of the HttpServletRequest parameters when in a servlet environment or a generic Map of parameters otherwise.jakarta.servlet.ServletContext
Gets ServletContext associated with current actionjakarta.servlet.http.HttpServletRequest
Gets ServletRequest associated with current actionjakarta.servlet.http.HttpServletResponse
Gets ServletResponse associated with current actionGets the Map of HttpSession values when in a servlet environment or a generic session map otherwise.Gets the OGNL value stack.final int
hashCode()
static ActionContext
of()
Creates a new ActionContext based on empty Mapstatic ActionContext
Creates a new ActionContext based on passed in Mapvoid
Stores a value in the current ActionContext.Adds arbitrary key to action contextwithActionInvocation
(ActionInvocation actionInvocation) Sets the action invocation (the execution state).withActionMapping
(ActionMapping actionMapping) Assigns ActionMapping to action contextwithActionName
(String actionName) Sets the name of the current Action in the ActionContext.withApplication
(Map<String, Object> application) Sets the action's application context.withContainer
(Container container) Gets the container for this requestwithConversionErrors
(Map<String, ConversionData> conversionErrors) Sets conversion errors which occurred when executing the action.withExtraContext
(Map<String, Object> extraContext) Assigns an extra context map to action contextwithLocale
(Locale locale) Sets the Locale for the current action.withPageContext
(jakarta.servlet.jsp.PageContext pageContext) Assigns PageContext to action contextwithParameters
(HttpParameters parameters) Sets the action parameters.withServletContext
(jakarta.servlet.ServletContext servletContext) Assigns ServletContext to action contextwithServletRequest
(jakarta.servlet.http.HttpServletRequest request) Assigns ServletRequest to action contextwithServletResponse
(jakarta.servlet.http.HttpServletResponse response) Assigns ServletResponse to action contextwithSession
(Map<String, Object> session) Sets a map of action session values.withValueStack
(ValueStack valueStack) Sets the OGNL value stack.
-
Constructor Details
-
ActionContext
Creates a new ActionContext initialized with another context.- Parameters:
context
- a context map.
-
-
Method Details
-
of
Creates a new ActionContext based on passed in Map- Parameters:
context
- a map with context values- Returns:
- new ActionContext
-
of
Creates a new ActionContext based on empty Map- Returns:
- new ActionContext
-
bind
Binds the provided context with the current thread- Parameters:
actionContext
- context to bind to the thread- Returns:
- context which was bound to the thread
-
containsValueStack
-
bind
Binds this context with the current thread- Returns:
- this context which was bound to the thread
-
clear
public static void clear()Wipes out current ActionContext, use wisely! -
getContext
Returns the ActionContext specific to the current thread.- Returns:
- the ActionContext for the current thread, is never null.
-
withActionInvocation
Sets the action invocation (the execution state).- Parameters:
actionInvocation
- the action execution state.
-
getActionInvocation
Gets the action invocation (the execution state).- Returns:
- the action invocation (the execution state).
-
withApplication
Sets the action's application context.- Parameters:
application
- the action's application context.
-
getApplication
Returns a Map of the ServletContext when in a servlet environment or a generic application level Map otherwise.- Returns:
- a Map of ServletContext or generic application level Map
-
getContextMap
Gets the context map.- Returns:
- the context map.
-
withConversionErrors
Sets conversion errors which occurred when executing the action.- Parameters:
conversionErrors
- a Map of errors which occurred when executing the action.
-
getConversionErrors
Gets the map of conversion errors which occurred when executing the action.- Returns:
- the map of conversion errors which occurred when executing the action or an empty map if there were no errors.
-
withLocale
Sets the Locale for the current action.- Parameters:
locale
- the Locale for the current action.
-
getLocale
Gets the Locale of the current action. If no locale was ever specified the platform'sdefault locale
is used.- Returns:
- the Locale of the current action.
-
withActionName
Sets the name of the current Action in the ActionContext.- Parameters:
actionName
- the name of the current action.
-
getActionName
Gets the name of the current Action.- Returns:
- the name of the current action.
-
withParameters
Sets the action parameters.- Parameters:
parameters
- the parameters for the current action.
-
getParameters
Returns a Map of the HttpServletRequest parameters when in a servlet environment or a generic Map of parameters otherwise.- Returns:
- a Map of HttpServletRequest parameters or a multipart map when in a servlet environment, or a generic Map of parameters otherwise.
-
withSession
Sets a map of action session values.- Parameters:
session
- the session values.
-
getSession
Gets the Map of HttpSession values when in a servlet environment or a generic session map otherwise.- Returns:
- the Map of HttpSession values when in a servlet environment or a generic session map otherwise.
-
withValueStack
Sets the OGNL value stack.- Parameters:
valueStack
- the OGNL value stack.
-
getValueStack
Gets the OGNL value stack.- Returns:
- the OGNL value stack.
-
withContainer
Gets the container for this request- Parameters:
container
- The container
-
getContainer
Sets the container for this request- Returns:
- The container
-
getInstance
-
get
Returns a value that is stored in the current ActionContext by doing a lookup using the value's key.- Parameters:
key
- the key used to find the value.- Returns:
- the value that was found using the key or null if the key was not found.
-
put
Stores a value in the current ActionContext. The value can be looked up using the key.- Parameters:
key
- the key of the value.value
- the value to be stored.
-
getServletContext
public jakarta.servlet.ServletContext getServletContext()Gets ServletContext associated with current action- Returns:
- current ServletContext
-
withServletContext
Assigns ServletContext to action context- Parameters:
servletContext
- associated with current request- Returns:
- ActionContext
-
getServletRequest
public jakarta.servlet.http.HttpServletRequest getServletRequest()Gets ServletRequest associated with current action- Returns:
- current ServletRequest
-
withServletRequest
Assigns ServletRequest to action context- Parameters:
request
- associated with current request- Returns:
- ActionContext
-
getServletResponse
public jakarta.servlet.http.HttpServletResponse getServletResponse()Gets ServletResponse associated with current action- Returns:
- current ServletResponse
-
withServletResponse
Assigns ServletResponse to action context- Parameters:
response
- associated with current request- Returns:
- ActionContext
-
getPageContext
public jakarta.servlet.jsp.PageContext getPageContext()Gets PageContext associated with current action- Returns:
- current PageContext
-
withPageContext
Assigns PageContext to action context- Parameters:
pageContext
- associated with current request- Returns:
- ActionContext
-
getActionMapping
Gets ActionMapping associated with current action- Returns:
- current ActionMapping
-
withActionMapping
Assigns ActionMapping to action context- Parameters:
actionMapping
- associated with current request- Returns:
- ActionContext
-
withExtraContext
Assigns an extra context map to action context- Parameters:
extraContext
- to add to the current action context- Returns:
- ActionContext
-
with
Adds arbitrary key to action context- Parameters:
key
- a stringvalue
- an object- Returns:
- ActionContext
-
equals
-
hashCode
public final int hashCode()
-