org.apache.struts2.portlet.util

## Class PortletUrlHelper

- java.lang.Object
- - org.apache.struts2.portlet.util.PortletUrlHelper

- Direct Known Subclasses:
    PortletUrlHelperJSR286

      public class PortletUrlHelper
      extends Object

  Helper class for creating Portlet URLs. Portlet URLs are fundamentally different from regular servlet URLs since they never target the application itself; all requests go through the portlet container and must therefore be programatically constructed using the `MimeResponse.createActionURL()` and `MimeResponse.createRenderURL()` APIs.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `ENCODING`
    `protected static String` | `PORTLETMODE_NAME_EDIT`
    `protected static String` | `PORTLETMODE_NAME_HELP`
    `protected static String` | `PORTLETMODE_NAME_VIEW`
    `protected static String` | `URLTYPE_NAME_ACTION`
    `protected static String` | `URLTYPE_NAME_RESOURCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PortletUrlHelper()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `buildResourceUrl(String value, Map params)` Encode an url to a non Struts action resource, like stylesheet, image or servlet.
    `String` | `buildUrl(String action, String namespace, String method, Map<String,Object> params, String type, String mode, String state)` Create a portlet URL with for the specified action and namespace.
    `String` | `buildUrl(String action, String namespace, String method, Map<String,Object> params, String scheme, String type, String portletMode, String windowState, boolean includeContext, boolean encodeResult)` Create a portlet URL with for the specified action and namespace.
    `protected Object` | `createUrl(String scheme, String type, Map<String,String[]> portletParams)`
    `protected String` | `encodeUrl(StringBuffer sb, javax.portlet.PortletRequest req)`
    `static Map<String,String[]>` | `ensureParamsAreStringArrays(Map<String,Object> params)` Will ensure that all entries in `params` are String arrays, as requried by the setParameters on the PortletURL.

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

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

- - ### Field Detail

    - #### ENCODING

          public static final String ENCODING

      See Also:
        Constant Field Values

    - #### PORTLETMODE_NAME_EDIT

          protected static final String PORTLETMODE_NAME_EDIT

      See Also:
        Constant Field Values

    - #### PORTLETMODE_NAME_VIEW

          protected static final String PORTLETMODE_NAME_VIEW

      See Also:
        Constant Field Values

    - #### PORTLETMODE_NAME_HELP

          protected static final String PORTLETMODE_NAME_HELP

      See Also:
        Constant Field Values

    - #### URLTYPE_NAME_ACTION

          protected static final String URLTYPE_NAME_ACTION

      See Also:
        Constant Field Values

    - #### URLTYPE_NAME_RESOURCE

          protected static final String URLTYPE_NAME_RESOURCE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### PortletUrlHelper

          public PortletUrlHelper()

  - ### Method Detail

    - #### buildUrl

          public String buildUrl(String action,
                                 String namespace,
                                 String method,
                                 Map<String,Object> params,
                                 String type,
                                 String mode,
                                 String state)

      Create a portlet URL with for the specified action and namespace.
      Parameters:
        `action` - The action the URL should invoke.
        `namespace` - The namespace of the action to invoke.
        `method` - The method of the action to invoke.
        `params` - The parameters of the URL.
        `type` - The type of the url, either `action` or `render`
        `mode` - The PortletMode of the URL.
        `state` - The WindowState of the URL.
      Returns:
        The URL String.

    - #### buildUrl

          public String buildUrl(String action,
                                 String namespace,
                                 String method,
                                 Map<String,Object> params,
                                 String scheme,
                                 String type,
                                 String portletMode,
                                 String windowState,
                                 boolean includeContext,
                                 boolean encodeResult)

      Create a portlet URL with for the specified action and namespace.
      Parameters:
        `action` - The action the URL should invoke.
        `namespace` - The namespace of the action to invoke.
        `method` - The method of the action to invoke.
        `params` - The parameters of the URL.
        `type` - The type of the url, either `action` or `render`
        `scheme` - The scheme of the URL.
        `portletMode` - The Portlet Mode of the URL.
        `windowState` - The Window State
        `includeContext` - true for including context
        `encodeResult` - true for encode of the result
      Returns:
        The URL String.
      See Also:
        `buildUrl(String, String, String, java.util.Map, String, String, String)`

    - #### createUrl

          protected Object createUrl(String scheme,
                                     String type,
                                     Map<String,String[]> portletParams)

    - #### buildResourceUrl

          public String buildResourceUrl(String value,
                                         Map params)

      Encode an url to a non Struts action resource, like stylesheet, image or servlet.
      Parameters:
        `value` - base url
        `params` - url parameters
      Returns:
        encoded url to non Struts action resources.

    - #### encodeUrl

          protected String encodeUrl(StringBuffer sb,
                                     javax.portlet.PortletRequest req)

    - #### ensureParamsAreStringArrays

          public static Map<String,String[]> ensureParamsAreStringArrays(Map<String,Object> params)

      Will ensure that all entries in `params` are String arrays, as requried by the setParameters on the PortletURL.
      Parameters:
        `params` - The parameters to the URL.
      Returns:
        A Map with all parameters as String arrays.

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