org.apache.struts2.portlet.result

## Class PortletActionRedirectResult

- java.lang.Object
- - org.apache.struts2.result.StrutsResultSupport
  - - org.apache.struts2.portlet.result.PortletResult
    - - org.apache.struts2.portlet.result.PortletActionRedirectResult

- All Implemented Interfaces:
    Result, Serializable, StrutsStatics

      public class PortletActionRedirectResult
      extends PortletResult

  Portlet modification of the `ServletActionRedirectResult`. This result uses the `ActionMapper` provided by the `ActionMapperFactory` to instruct the render phase to invoke the specified action and (optional) namespace. This is better than the `PortletResult` because it does not require you to encode the URL patterns processed by the `ActionMapper` in to your struts.xml configuration files. This means you can change your URL patterns at any point and your application will still work. It is strongly recommended that if you are redirecting to another action, you use this result rather than the standard redirect result. See examples below for an example of how request parameters could be passed in. This result type takes the following parameters:
  - actionName (default) - the name of the action that will be redirect to
  - namespace - used to determine which namespace the action is in that we're redirecting to . If namespace is null, this defaults to the current namespace
  Example:

       <!-- START SNIPPET: example -->
        <package name="public" extends="struts-default">
            <action name="login" class="...">
                <!-- Redirect to another namespace -->
                <result type="redirect-action">
                    <param name="actionName">dashboard</param>
                    <param name="namespace">/secure</param>
                </result>
            </action>
        </package>

        <package name="secure" extends="struts-default" namespace="/secure">
            <-- Redirect to an action in the same namespace -->
            <action name="dashboard" class="...">
                <result>dashboard.jsp</result>
                <result name="error" type="redirect-action">error</result>
            </action>

            <action name="error" class="...">
                <result>error.jsp</result>
            </action>
        </package>

        <package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters">
           <-- Pass parameters (reportType, width and height) -->
           <!--
           The redirect-action url generated will be :
           /genReport/generateReport.action?reportType=pie&width=100&height=100
           -->
           <action name="gatherReportInfo" class="...">
              <result name="showReportResult" type="redirect-action">
                 <param name="actionName">generateReport</param>
                 <param name="namespace">/genReport</param>
                 <param name="reportType">pie</param>
                 <param name="width">100</param>
                 <param name="height">100</param>
              </result>
           </action>
        </package>

        <!-- END SNIPPET: example -->

  See Also:
    `ActionMapper`, Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected String` | `actionName`
    `static String` | `DEFAULT_PARAM` The default parameter
    `protected String` | `method`
    `protected String` | `namespace`
    `protected List<String>` | `prohibitedResultParam`

    - ### Fields inherited from class org.apache.struts2.portlet.result.PortletResult

      `portletMode`

    - ### Fields inherited from class org.apache.struts2.result.StrutsResultSupport

      `DEFAULT_URL_ENCODING, parseLocation`

    - ### Fields inherited from interface org.apache.struts2.StrutsStatics

      `HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PortletActionRedirectResult()`
    `PortletActionRedirectResult(String actionName)`
    `PortletActionRedirectResult(String actionName, String method)`
    `PortletActionRedirectResult(String namespace, String actionName, String method)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `PortletActionRedirectResult` | `addParameter(String key, Object value)` Adds a request parameter to be added to the redirect url
    `void` | `execute(ActionInvocation invocation)`
    `void` | `setActionMapper(ActionMapper actionMapper)`
    `void` | `setActionName(String actionName)` Sets the action name
    `void` | `setMethod(String method)` Sets the method
    `void` | `setNamespace(String namespace)` Sets the namespace
    `void` | `setUrlHelper(UrlHelper urlHelper)`

    - ### Methods inherited from class org.apache.struts2.portlet.result.PortletResult

      `convertQueryParamsToRenderParams, doExecute, executeActionResult, executeMimeResult, setContentType, setDispatcherServletName, setPortletMode, setTitle, setUseDispatcherServlet`

    - ### Methods inherited from class org.apache.struts2.result.StrutsResultSupport

      `conditionalParse, conditionalParseCollection, getLastFinalLocation, getLocation, setEncode, setLocation, setParse`

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

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

- - ### Field Detail

    - #### DEFAULT_PARAM

          public static final String DEFAULT_PARAM

      The default parameter
      See Also:
        Constant Field Values

    - #### actionName

          protected String actionName

    - #### namespace

          protected String namespace

    - #### method

          protected String method

    - #### prohibitedResultParam

          protected List<String> prohibitedResultParam

  - ### Constructor Detail

    - #### PortletActionRedirectResult

          public PortletActionRedirectResult()

    - #### PortletActionRedirectResult

          public PortletActionRedirectResult(String actionName)

    - #### PortletActionRedirectResult

          public PortletActionRedirectResult(String actionName,
                                     String method)

    - #### PortletActionRedirectResult

          public PortletActionRedirectResult(String namespace,
                                     String actionName,
                                     String method)

  - ### Method Detail

    - #### setActionMapper

          public void setActionMapper(ActionMapper actionMapper)

    - #### setUrlHelper

          public void setUrlHelper(UrlHelper urlHelper)

    - #### execute

          public void execute(ActionInvocation invocation)
                       throws Exception

      Specified by:
        `execute` in interface `Result`
      Overrides:
        `execute` in class `StrutsResultSupport`
      Throws:
        `Exception`
      See Also:
        `Result.execute(com.opensymphony.xwork2.ActionInvocation)`

    - #### setActionName

          public void setActionName(String actionName)

      Sets the action name
      Parameters:
        `actionName` - The name

    - #### setNamespace

          public void setNamespace(String namespace)

      Sets the namespace
      Parameters:
        `namespace` - The namespace

    - #### setMethod

          public void setMethod(String method)

      Sets the method
      Parameters:
        `method` - The method

    - #### addParameter

          public PortletActionRedirectResult addParameter(String key,
                                                 Object value)

      Adds a request parameter to be added to the redirect url
      Parameters:
        `key` - The parameter name
        `value` - The parameter value
      Returns:
        the portlet action redirect result

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