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 and Type | Field and Description |
---|---|
static String |
ACTION_INVOCATION
Deprecated.
scope will be narrowed to "private", use helper methods instead
|
static String |
ACTION_NAME
Deprecated.
scope will be narrowed to "private", use helper methods instead
|
static String |
APPLICATION
Deprecated.
scope will be narrowed to "private", use helper methods instead
|
static String |
CONTAINER
Deprecated.
scope will be narrowed to "private", use helper methods instead
|
static String |
CONVERSION_ERRORS
Deprecated.
scope will be narrowed to "private", use helper methods instead
|
static String |
LOCALE
Deprecated.
scope will be narrowed to "private", use helper methods instead
|
static String |
PARAMETERS
Deprecated.
scope will be narrowed to "private", use helper methods instead
|
static String |
SESSION
Deprecated.
scope will be narrowed to "private", use helper methods instead
|
static String |
VALUE_STACK
Deprecated.
scope will be narrowed to "private", use helper methods instead
|
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) |
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.
|
String |
getName()
Gets the name 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.
|
static ActionContext |
of(Map<String,Object> context)
Creates a new ActionContext based on passed in Map
and assign this instance to the current thread
|
void |
put(String key,
Object value)
Stores a value in the current ActionContext.
|
void |
setActionInvocation(ActionInvocation actionInvocation)
Deprecated.
use
withActionInvocation(ActionInvocation) instead |
void |
setApplication(Map<String,Object> application)
Deprecated.
use
withApplication(Map) instead |
void |
setContainer(Container cont)
Deprecated.
use
withContainer(Container) instead |
void |
setConversionErrors(Map<String,ConversionData> conversionErrors)
Deprecated.
use
withConversionErrors(Map) instead |
void |
setLocale(Locale locale)
Deprecated.
use
withLocale(Locale) instead |
void |
setName(String name)
Deprecated.
use
withActionName(String) instead |
void |
setParameters(HttpParameters parameters)
Sets the action parameters.
|
void |
setSession(Map<String,Object> session)
Deprecated.
use
withSession(Map) instead |
void |
setValueStack(ValueStack stack)
Deprecated.
Use
withValueStack(ValueStack) instead |
ActionContext |
with(String key,
Object value)
Adds arbitrary key to action context
|
ActionContext |
withActionInvocation(ActionInvocation actionInvocation) |
ActionContext |
withActionMapping(ActionMapping actionMapping)
Assigns ActionMapping to action context
|
ActionContext |
withActionName(String actionName) |
ActionContext |
withApplication(Map<String,Object> application) |
ActionContext |
withContainer(Container container) |
ActionContext |
withConversionErrors(Map<String,ConversionData> conversionErrors) |
ActionContext |
withExtraContext(Map<String,Object> extraContext)
Assigns an extra context map to action context
|
ActionContext |
withLocale(Locale locale) |
ActionContext |
withPageContext(javax.servlet.jsp.PageContext pageContext)
Assigns PageContext to action context
|
ActionContext |
withParameters(HttpParameters 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) |
ActionContext |
withValueStack(ValueStack valueStack) |
@Deprecated public static final String ACTION_NAME
@Deprecated public static final String VALUE_STACK
OGNL value stack
.@Deprecated public static final String SESSION
@Deprecated public static final String APPLICATION
@Deprecated public static final String PARAMETERS
@Deprecated public static final String LOCALE
@Deprecated public static final String ACTION_INVOCATION
invocation
context.@Deprecated public static final String CONVERSION_ERRORS
@Deprecated public static final String CONTAINER
public static ActionContext of(Map<String,Object> context)
context
- a map with context valuespublic static ActionContext bind(ActionContext actionContext)
actionContext
- context to bind to the threadpublic ActionContext bind()
public static void clear()
public static ActionContext getContext()
@Deprecated public void setActionInvocation(ActionInvocation actionInvocation)
withActionInvocation(ActionInvocation)
insteadactionInvocation
- the action execution state.public ActionContext withActionInvocation(ActionInvocation actionInvocation)
public ActionInvocation getActionInvocation()
@Deprecated public void setApplication(Map<String,Object> application)
withApplication(Map)
insteadapplication
- the action's application context.public ActionContext withApplication(Map<String,Object> application)
public Map<String,Object> getApplication()
public Map<String,Object> getContextMap()
@Deprecated public void setConversionErrors(Map<String,ConversionData> conversionErrors)
withConversionErrors(Map)
insteadconversionErrors
- a Map of errors which occurred when executing the action.public ActionContext withConversionErrors(Map<String,ConversionData> conversionErrors)
public Map<String,ConversionData> getConversionErrors()
@Deprecated public void setLocale(Locale locale)
withLocale(Locale)
insteadlocale
- the Locale for the current action.public ActionContext withLocale(Locale locale)
public Locale getLocale()
default locale
is used.@Deprecated public void setName(String name)
withActionName(String)
insteadname
- the name of the current action.public ActionContext withActionName(String actionName)
public String getName()
public String getActionName()
public void setParameters(HttpParameters parameters)
parameters
- the parameters for the current action.public ActionContext withParameters(HttpParameters parameters)
public HttpParameters getParameters()
@Deprecated public void setSession(Map<String,Object> session)
withSession(Map)
insteadsession
- the session values.public ActionContext withSession(Map<String,Object> session)
public Map<String,Object> getSession()
@Deprecated public void setValueStack(ValueStack stack)
withValueStack(ValueStack)
insteadstack
- the OGNL value stack.public ActionContext withValueStack(ValueStack valueStack)
public ValueStack getValueStack()
@Deprecated public void setContainer(Container cont)
withContainer(Container)
insteadcont
- The containerpublic ActionContext withContainer(Container container)
public 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–2023 Apache Software Foundation. All rights reserved.