org.apache.struts2.components

## Class ActionComponent

- java.lang.Object
- - org.apache.struts2.components.Component
  - - org.apache.struts2.components.ContextBean
    - - org.apache.struts2.components.ActionComponent

-     public class ActionComponent
      extends ContextBean

  This tag enables developers to call actions directly from a JSP page by specifying the action name and an optional namespace. The body content of the tag is used to render the results from the Action. Any result processor defined for this action in struts.xml will be ignored, unless the executeResult parameter is specified.

  - id (String) - the id (if specified) to put the action under stack's context.
  - name* (String) - name of the action to be executed (without the extension suffix eg. .action)
  - namespace (String) - default to the namespace where this action tag is invoked
  - executeResult (Boolean) - default is false. Decides whether the result of this action is to be executed or not
  - ignoreContextParams (Boolean) - default to false. Decides whether the request parameters are to be included when the action is invoked

       public class ActionTagAction extends ActionSupport {

        public String execute() throws Exception {
            return "done";
        }

        public String doDefault() throws Exception {
            ServletActionContext.getRequest().setAttribute("stringByAction", "This is a String put in by the action's doDefault()");
            return "done";
        }
       }

         <xwork>
            ....
           <action name="actionTagAction1" class="tmjee.testing.ActionTagAction">
               <result name="done">success.jsp</result>
           </action>
            <action name="actionTagAction2" class="tmjee.testing.ActionTagAction" method="default">
               <result name="done">success.jsp</result>
           </action>
            ....
         </xwork>

        The following action tag will execute result and include it in this page

        <s:action name="actionTagAction" executeResult="true" />

        The following action tag will do the same as above, but invokes method specialMethod in action

        <s:action name="actionTagAction!specialMethod" executeResult="true" />

        The following action tag will not execute result, but put a String in request scope
             under an id "stringByAction" which will be retrieved using property tag
        <s:action name="actionTagAction!default" executeResult="false" />
        <s:property value="#attr.stringByAction" />

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ActionProxyFactory` | `actionProxyFactory`
    `protected boolean` | `executeResult`
    `protected boolean` | `flush`
    `protected boolean` | `ignoreContextParams`
    `protected String` | `name`
    `protected String` | `namespace`
    `protected ActionProxy` | `proxy`
    `protected javax.servlet.http.HttpServletRequest` | `req`
    `protected javax.servlet.http.HttpServletResponse` | `res`
    `protected boolean` | `rethrowException`
    `protected ValueStackFactory` | `valueStackFactory`

    - ### Fields inherited from class org.apache.struts2.components.ContextBean

      `var`

    - ### Fields inherited from class org.apache.struts2.components.Component

      `actionMapper, COMPONENT_STACK, devMode, escapeHtmlBody, parameters, performClearTagStateForTagPoolingServers, stack, standardAttributesMap, throwExceptionOnELFailure`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ActionComponent(ValueStack stack, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Map<String,Object>` | `createExtraContext()`
    `protected HttpParameters` | `createParametersForContext()` Creates parameters map using parameters from the value stack and component parameters.
    `boolean` | `end(Writer writer, String body)` Callback for the end tag of this component.
    `protected void` | `executeAction()` Execute the requested action.
    `ActionProxy` | `getProxy()`
    `void` | `setActionMapper(ActionMapper mapper)`
    `void` | `setActionProxyFactory(ActionProxyFactory actionProxyFactory)`
    `void` | `setExecuteResult(boolean executeResult)`
    `void` | `setFlush(boolean flush)`
    `void` | `setIgnoreContextParams(boolean ignoreContextParams)`
    `void` | `setName(String name)`
    `void` | `setNamespace(String namespace)`
    `void` | `setRethrowException(boolean rethrowException)`
    `void` | `setValueStackFactory(ValueStackFactory valueStackFactory)`

    - ### Methods inherited from class org.apache.struts2.components.ContextBean

      `getVar, putInContext, setVar`

    - ### Methods inherited from class org.apache.struts2.components.Component

      `addAllParameters, addParameter, completeExpression, copyParams, determineActionURL, determineNamespace, end, escapeHtmlBody, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getAttributes, getComponentStack, getNamespace, getParameters, getPerformClearTagStateForTagPoolingServers, getStack, getStandardAttributes, isAcceptableExpression, isValidTagAttribute, popComponentStack, setDevMode, setEscapeHtmlBody, setNotExcludedAcceptedPatterns, setPerformClearTagStateForTagPoolingServers, setThrowExceptionsOnELFailure, setUrlHelper, start, stripExpression, toString, usesBody`

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

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

- - ### Field Detail

    - #### res

          protected javax.servlet.http.HttpServletResponse res

    - #### req

          protected javax.servlet.http.HttpServletRequest req

    - #### valueStackFactory

          protected ValueStackFactory valueStackFactory

    - #### actionProxyFactory

          protected ActionProxyFactory actionProxyFactory

    - #### proxy

          protected ActionProxy proxy

    - #### name

          protected String name

    - #### namespace

          protected String namespace

    - #### executeResult

          protected boolean executeResult

    - #### ignoreContextParams

          protected boolean ignoreContextParams

    - #### flush

          protected boolean flush

    - #### rethrowException

          protected boolean rethrowException

  - ### Constructor Detail

    - #### ActionComponent

          public ActionComponent(ValueStack stack,
                                 javax.servlet.http.HttpServletRequest req,
                                 javax.servlet.http.HttpServletResponse res)

  - ### Method Detail

    - #### setActionProxyFactory

          public void setActionProxyFactory(ActionProxyFactory actionProxyFactory)

      Parameters:
        `actionProxyFactory` - the actionProxyFactory to set

    - #### setValueStackFactory

          public void setValueStackFactory(ValueStackFactory valueStackFactory)

    - #### setActionMapper

          public void setActionMapper(ActionMapper mapper)

      Overrides:
        `setActionMapper` in class `Component`

    - #### end

          public boolean end(Writer writer,
                             String body)

      Description copied from class: `Component`
      Callback for the end tag of this component. Should the body be evaluated again?
      NOTE: will pop component stack.
      Overrides:
        `end` in class `Component`
      Parameters:
        `writer` - the output writer.
        `body` - the rendered body.
      Returns:
        true if the body should be evaluated again

    - #### createExtraContext

          protected Map<String,Object> createExtraContext()

    - #### createParametersForContext

          protected HttpParameters createParametersForContext()

      Creates parameters map using parameters from the value stack and component parameters. Any non-String array values will be converted into a single-value String array.
      Returns:
        A map of String[] parameters

    - #### getProxy

          public ActionProxy getProxy()

    - #### executeAction

          protected void executeAction()

      Execute the requested action. If no namespace is provided, we'll attempt to derive a namespace using buildNamespace(). The ActionProxy and the namespace will be saved into the instance variables proxy and namespace respectively.

    - #### setName

          public void setName(String name)

    - #### setNamespace

          public void setNamespace(String namespace)

    - #### setExecuteResult

          public void setExecuteResult(boolean executeResult)

    - #### setIgnoreContextParams

          public void setIgnoreContextParams(boolean ignoreContextParams)

    - #### setFlush

          public void setFlush(boolean flush)

    - #### setRethrowException

          public void setRethrowException(boolean rethrowException)

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