public class ActionContext extends Object implements 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.
Modifier | Constructor and Description |
---|---|
protected |
ActionContext(Map<String,Object> context)
Creates a new ActionContext initialized with another context.
|
Modifier and Type | Method and Description |
---|---|
ActionContext |
bind()
Binds this context with the current thread
|
static ActionContext |
bind(ActionContext actionContext)
Binds the provided context with the current thread
|
static void |
clear()
Wipes out current ActionContext, use wisely!
|
static boolean |
containsValueStack(Map<String,Object> context) |
boolean |
equals(Object obj) |
Object |
get(String key)
Returns a value that is stored in the current ActionContext by doing a lookup using the value's key.
|
ActionInvocation |
getActionInvocation()
Gets the action invocation (the execution state).
|
ActionMapping |
getActionMapping()
Gets ActionMapping associated with current action
|
String |
getActionName()
Gets the name of the current Action.
|
Map<String,Object> |
getApplication()
Returns a Map of the ServletContext when in a servlet environment or a generic application level Map otherwise.
|
Container |
getContainer()
Sets the container for this request
|
static ActionContext |
getContext()
Returns the ActionContext specific to the current thread.
|
Map<String,Object> |
getContextMap()
Gets the context map.
|
Map<String,ConversionData> |
getConversionErrors()
Gets the map of conversion errors which occurred when executing the action.
|
<T> T |
getInstance(Class<T> type) |
Locale |
getLocale()
Gets the Locale of the current action.
|
javax.servlet.jsp.PageContext |
getPageContext()
Gets PageContext associated with current action
|
HttpParameters |
getParameters()
Returns a Map of the HttpServletRequest parameters when in a servlet environment or a generic Map of
parameters otherwise.
|
javax.servlet.ServletContext |
getServletContext()
Gets ServletContext associated with current action
|
javax.servlet.http.HttpServletRequest |
getServletRequest()
Gets ServletRequest associated with current action
|
javax.servlet.http.HttpServletResponse |
getServletResponse()
Gets ServletResponse associated with current action
|
Map<String,Object> |
getSession()
Gets the Map of HttpSession values when in a servlet environment or a generic session map otherwise.
|
ValueStack |
getValueStack()
Gets the OGNL value stack.
|
int |
hashCode() |
static ActionContext |
of()
Creates a new ActionContext based on empty Map
|
static ActionContext |
of(Map<String,Object> context)
Creates a new ActionContext based on passed in Map
|
void |
put(String key,
Object value)
Stores a value in the current ActionContext.
|
ActionContext |
with(String key,
Object value)
Adds arbitrary key to action context
|
ActionContext |
withActionInvocation(ActionInvocation actionInvocation)
Sets the action invocation (the execution state).
|
ActionContext |
withActionMapping(ActionMapping actionMapping)
Assigns ActionMapping to action context
|
ActionContext |
withActionName(String actionName)
Sets the name of the current Action in the ActionContext.
|
ActionContext |
withApplication(Map<String,Object> application)
Sets the action's application context.
|
ActionContext |
withContainer(Container container)
Gets the container for this request
|
ActionContext |
withConversionErrors(Map<String,ConversionData> conversionErrors)
Sets conversion errors which occurred when executing the action.
|
ActionContext |
withExtraContext(Map<String,Object> extraContext)
Assigns an extra context map to action context
|
ActionContext |
withLocale(Locale locale)
Sets the Locale for the current action.
|
ActionContext |
withPageContext(javax.servlet.jsp.PageContext pageContext)
Assigns PageContext to action context
|
ActionContext |
withParameters(HttpParameters parameters)
Sets the action parameters.
|
ActionContext |
withServletContext(javax.servlet.ServletContext servletContext)
Assigns ServletContext to action context
|
ActionContext |
withServletRequest(javax.servlet.http.HttpServletRequest request)
Assigns ServletRequest to action context
|
ActionContext |
withServletResponse(javax.servlet.http.HttpServletResponse response)
Assigns ServletResponse to action context
|
ActionContext |
withSession(Map<String,Object> session)
Sets a map of action session values.
|
ActionContext |
withValueStack(ValueStack valueStack)
Sets the OGNL value stack.
|
public static ActionContext of(Map<String,Object> context)
context
- a map with context valuespublic static ActionContext of()
public static ActionContext bind(ActionContext actionContext)
actionContext
- context to bind to the threadpublic ActionContext bind()
public static void clear()
public static ActionContext getContext()
public ActionContext withActionInvocation(ActionInvocation actionInvocation)
actionInvocation
- the action execution state.public ActionInvocation getActionInvocation()
public ActionContext withApplication(Map<String,Object> application)
application
- the action's application context.public Map<String,Object> getApplication()
public Map<String,Object> getContextMap()
public ActionContext withConversionErrors(Map<String,ConversionData> conversionErrors)
conversionErrors
- a Map of errors which occurred when executing the action.public Map<String,ConversionData> getConversionErrors()
public ActionContext withLocale(Locale locale)
locale
- the Locale for the current action.public Locale getLocale()
default locale
is used.public ActionContext withActionName(String actionName)
actionName
- the name of the current action.public String getActionName()
public ActionContext withParameters(HttpParameters parameters)
parameters
- the parameters for the current action.public HttpParameters getParameters()
public ActionContext withSession(Map<String,Object> session)
session
- the session values.public Map<String,Object> getSession()
public ActionContext withValueStack(ValueStack valueStack)
valueStack
- the OGNL value stack.public ValueStack getValueStack()
public ActionContext withContainer(Container container)
container
- The containerpublic Container getContainer()
public <T> T getInstance(Class<T> type)
public Object get(String key)
key
- the key used to find the value.public void put(String key, Object value)
key
- the key of the value.value
- the value to be stored.public javax.servlet.ServletContext getServletContext()
public ActionContext withServletContext(javax.servlet.ServletContext servletContext)
servletContext
- associated with current requestpublic javax.servlet.http.HttpServletRequest getServletRequest()
public ActionContext withServletRequest(javax.servlet.http.HttpServletRequest request)
request
- associated with current requestpublic javax.servlet.http.HttpServletResponse getServletResponse()
public ActionContext withServletResponse(javax.servlet.http.HttpServletResponse response)
response
- associated with current requestpublic javax.servlet.jsp.PageContext getPageContext()
public ActionContext withPageContext(javax.servlet.jsp.PageContext pageContext)
pageContext
- associated with current requestpublic ActionMapping getActionMapping()
public ActionContext withActionMapping(ActionMapping actionMapping)
actionMapping
- associated with current requestpublic ActionContext withExtraContext(Map<String,Object> extraContext)
extraContext
- to add to the current action contextpublic ActionContext with(String key, Object value)
key
- a stringvalue
- an objectCopyright © 2000–2024 Apache Software Foundation. All rights reserved.