com.opensymphony.xwork2

## Class ActionContext

- java.lang.Object
- - com.opensymphony.xwork2.ActionContext

- All Implemented Interfaces:
    Serializable

      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.

  Author:
    Patrick Lightbody, Bill Lynch (docs)
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    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

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ActionContext(Map<String,Object> context)` Creates a new ActionContext initialized with another context.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    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)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ACTION_NAME

          @Deprecated
          public static final String ACTION_NAME

      Deprecated. scope will be narrowed to "private", use helper methods instead
      Constant for the name of the action being executed.
      See Also:
        Constant Field Values

    - #### VALUE_STACK

          @Deprecated
          public static final String VALUE_STACK

      Deprecated. scope will be narrowed to "private", use helper methods instead
      Constant for the `OGNL value stack`.
      See Also:
        Constant Field Values

    - #### SESSION

          @Deprecated
          public static final String SESSION

      Deprecated. scope will be narrowed to "private", use helper methods instead
      Constant for the action's session.
      See Also:
        Constant Field Values

    - #### APPLICATION

          @Deprecated
          public static final String APPLICATION

      Deprecated. scope will be narrowed to "private", use helper methods instead
      Constant for the action's application context.
      See Also:
        Constant Field Values

    - #### PARAMETERS

          @Deprecated
          public static final String PARAMETERS

      Deprecated. scope will be narrowed to "private", use helper methods instead
      Constant for the action's parameters.
      See Also:
        Constant Field Values

    - #### LOCALE

          @Deprecated
          public static final String LOCALE

      Deprecated. scope will be narrowed to "private", use helper methods instead
      Constant for the action's locale.
      See Also:
        Constant Field Values

    - #### ACTION_INVOCATION

          @Deprecated
          public static final String ACTION_INVOCATION

      Deprecated. scope will be narrowed to "private", use helper methods instead
      Constant for the action's `invocation` context.
      See Also:
        Constant Field Values

    - #### CONVERSION_ERRORS

          @Deprecated
          public static final String CONVERSION_ERRORS

      Deprecated. scope will be narrowed to "private", use helper methods instead
      Constant for the map of type conversion errors.
      See Also:
        Constant Field Values

    - #### CONTAINER

          @Deprecated
          public static final String CONTAINER

      Deprecated. scope will be narrowed to "private", use helper methods instead
      Constant for the container
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ActionContext

          protected ActionContext(Map<String,Object> context)

      Creates a new ActionContext initialized with another context.
      Parameters:
        `context` - a context map.

  - ### Method Detail

    - #### of

          public static ActionContext of(Map<String,Object> context)

      Creates a new ActionContext based on passed in Map and assign this instance to the current thread
      Parameters:
        `context` - a map with context values
      Returns:
        new ActionContext

    - #### bind

          public static ActionContext bind(ActionContext actionContext)

      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

          public static boolean containsValueStack(Map<String,Object> context)

    - #### bind

          public ActionContext 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

          public static ActionContext getContext()

      Returns the ActionContext specific to the current thread.
      Returns:
        the ActionContext for the current thread, is never `null`.

    - #### setActionInvocation

          @Deprecated
          public void setActionInvocation(ActionInvocation actionInvocation)

      Deprecated. use `withActionInvocation(ActionInvocation)` instead
      Sets the action invocation (the execution state).
      Parameters:
        `actionInvocation` - the action execution state.

    - #### withActionInvocation

          public ActionContext withActionInvocation(ActionInvocation actionInvocation)

    - #### getActionInvocation

          public ActionInvocation getActionInvocation()

      Gets the action invocation (the execution state).
      Returns:
        the action invocation (the execution state).

    - #### setApplication

          @Deprecated
          public void setApplication(Map<String,Object> application)

      Deprecated. use `withApplication(Map)` instead
      Sets the action's application context.
      Parameters:
        `application` - the action's application context.

    - #### withApplication

          public ActionContext withApplication(Map<String,Object> application)

    - #### getApplication

          public Map<String,Object> 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

          public Map<String,Object> getContextMap()

      Gets the context map.
      Returns:
        the context map.

    - #### setConversionErrors

          @Deprecated
          public void setConversionErrors(Map<String,ConversionData> conversionErrors)

      Deprecated. use `withConversionErrors(Map)` instead
      Sets conversion errors which occurred when executing the action.
      Parameters:
        `conversionErrors` - a Map of errors which occurred when executing the action.

    - #### withConversionErrors

          public ActionContext withConversionErrors(Map<String,ConversionData> conversionErrors)

    - #### getConversionErrors

          public Map<String,ConversionData> 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.

    - #### setLocale

          @Deprecated
          public void setLocale(Locale locale)

      Deprecated. use `withLocale(Locale)` instead
      Sets the Locale for the current action.
      Parameters:
        `locale` - the Locale for the current action.

    - #### withLocale

          public ActionContext withLocale(Locale locale)

    - #### getLocale

          public Locale getLocale()

      Gets the Locale of the current action. If no locale was ever specified the platform's `default locale` is used.
      Returns:
        the Locale of the current action.

    - #### setName

          @Deprecated
          public void setName(String name)

      Deprecated. use `withActionName(String)` instead
      Sets the name of the current Action in the ActionContext.
      Parameters:
        `name` - the name of the current action.

    - #### withActionName

          public ActionContext withActionName(String actionName)

    - #### getName

          public String getName()

      Gets the name of the current Action.
      Returns:
        the name of the current action.

    - #### getActionName

          public String getActionName()

      Gets the name of the current Action.
      Returns:
        the name of the current action.

    - #### setParameters

          public void setParameters(HttpParameters parameters)

      Sets the action parameters.
      Parameters:
        `parameters` - the parameters for the current action.

    - #### withParameters

          public ActionContext withParameters(HttpParameters parameters)

    - #### getParameters

          public HttpParameters 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.

    - #### setSession

          @Deprecated
          public void setSession(Map<String,Object> session)

      Deprecated. use `withSession(Map)` instead
      Sets a map of action session values.
      Parameters:
        `session` - the session values.

    - #### withSession

          public ActionContext withSession(Map<String,Object> session)

    - #### getSession

          public Map<String,Object> 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.

    - #### setValueStack

          @Deprecated
          public void setValueStack(ValueStack stack)

      Deprecated. Use `withValueStack(ValueStack)` instead
      Sets the OGNL value stack.
      Parameters:
        `stack` - the OGNL value stack.

    - #### withValueStack

          public ActionContext withValueStack(ValueStack valueStack)

    - #### getValueStack

          public ValueStack getValueStack()

      Gets the OGNL value stack.
      Returns:
        the OGNL value stack.

    - #### setContainer

          @Deprecated
          public void setContainer(Container cont)

      Deprecated. use `withContainer(Container)` instead
      Gets the container for this request
      Parameters:
        `cont` - The container

    - #### withContainer

          public ActionContext withContainer(Container container)

    - #### getContainer

          public Container getContainer()

      Sets the container for this request
      Returns:
        The container

    - #### getInstance

          public <T> T getInstance(Class<T> type)

    - #### get

          public Object get(String key)

      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

          public void put(String key,
                          Object value)

      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 javax.servlet.ServletContext getServletContext()

      Gets ServletContext associated with current action
      Returns:
        current ServletContext

    - #### withServletContext

          public ActionContext withServletContext(javax.servlet.ServletContext servletContext)

      Assigns ServletContext to action context
      Parameters:
        `servletContext` - associated with current request
      Returns:
        ActionContext

    - #### getServletRequest

          public javax.servlet.http.HttpServletRequest getServletRequest()

      Gets ServletRequest associated with current action
      Returns:
        current ServletRequest

    - #### withServletRequest

          public ActionContext withServletRequest(javax.servlet.http.HttpServletRequest request)

      Assigns ServletRequest to action context
      Parameters:
        `request` - associated with current request
      Returns:
        ActionContext

    - #### getServletResponse

          public javax.servlet.http.HttpServletResponse getServletResponse()

      Gets ServletResponse associated with current action
      Returns:
        current ServletResponse

    - #### withServletResponse

          public ActionContext withServletResponse(javax.servlet.http.HttpServletResponse response)

      Assigns ServletResponse to action context
      Parameters:
        `response` - associated with current request
      Returns:
        ActionContext

    - #### getPageContext

          public javax.servlet.jsp.PageContext getPageContext()

      Gets PageContext associated with current action
      Returns:
        current PageContext

    - #### withPageContext

          public ActionContext withPageContext(javax.servlet.jsp.PageContext pageContext)

      Assigns PageContext to action context
      Parameters:
        `pageContext` - associated with current request
      Returns:
        ActionContext

    - #### getActionMapping

          public ActionMapping getActionMapping()

      Gets ActionMapping associated with current action
      Returns:
        current ActionMapping

    - #### withActionMapping

          public ActionContext withActionMapping(ActionMapping actionMapping)

      Assigns ActionMapping to action context
      Parameters:
        `actionMapping` - associated with current request
      Returns:
        ActionContext

    - #### withExtraContext

          public ActionContext withExtraContext(Map<String,Object> extraContext)

      Assigns an extra context map to action context
      Parameters:
        `extraContext` - to add to the current action context
      Returns:
        ActionContext

    - #### with

          public ActionContext with(String key,
                                    Object value)

      Adds arbitrary key to action context
      Parameters:
        `key` - a string
        `value` - an object
      Returns:
        ActionContext

Copyright © 2000–2023 Apache Software Foundation. All rights reserved.