org.apache.struts2.util

## Class StrutsUtil

- java.lang.Object
- - org.apache.struts2.util.StrutsUtil

- Direct Known Subclasses:
    VelocityStrutsUtil

      public class StrutsUtil
      extends Object

  Struts base utility class, for use in Velocity and Freemarker templates

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Map<String,Class>` | `classes`
    `protected static org.apache.logging.log4j.Logger` | `LOG`
    `protected OgnlTool` | `ognl`
    `protected javax.servlet.http.HttpServletRequest` | `request`
    `protected javax.servlet.http.HttpServletResponse` | `response`
    `protected ValueStack` | `stack`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StrutsUtil(ValueStack stack, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `bean(Object aName)`
    `String` | `buildUrl(String url)`
    `Object` | `findString(String name)`
    `Object` | `findValue(String expression, String className)`
    `String` | `getContext()`
    `String` | `getText(String text)`
    `String` | `include(Object aName)`
    `boolean` | `isTrue(String expression)`
    `List` | `makeSelectList(String selectedList, String list, String listKey, String listValue)` the selectedList objects are matched to the list.listValue
    `int` | `toInt(long aLong)`
    `long` | `toLong(int anInt)`
    `long` | `toLong(String aLong)`
    `String` | `toString(int anInt)`
    `String` | `toString(long aLong)`
    `String` | `toStringSafe(Object obj)`
    `String` | `translateVariables(String expression)`
    `String` | `urlEncode(String s)`

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

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

- - ### Field Detail

    - #### LOG

          protected static final org.apache.logging.log4j.Logger LOG

    - #### request

          protected javax.servlet.http.HttpServletRequest request

    - #### response

          protected javax.servlet.http.HttpServletResponse response

    - #### classes

          protected Map<String,Class> classes

    - #### ognl

          protected OgnlTool ognl

    - #### stack

          protected ValueStack stack

  - ### Constructor Detail

    - #### StrutsUtil

          public StrutsUtil(ValueStack stack,
                    javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)

  - ### Method Detail

    - #### bean

          public Object bean(Object aName)
                      throws Exception

      Throws:
        `Exception`

    - #### isTrue

          public boolean isTrue(String expression)

    - #### findString

          public Object findString(String name)

    - #### include

          public String include(Object aName)
                         throws Exception

      Throws:
        `Exception`

    - #### urlEncode

          public String urlEncode(String s)

    - #### buildUrl

          public String buildUrl(String url)

    - #### findValue

          public Object findValue(String expression,
                         String className)
                           throws ClassNotFoundException

      Throws:
        `ClassNotFoundException`

    - #### getText

          public String getText(String text)

    - #### getContext

          public String getContext()

    - #### translateVariables

          public String translateVariables(String expression)

    - #### makeSelectList

          public List makeSelectList(String selectedList,
                            String list,
                            String listKey,
                            String listValue)

      the selectedList objects are matched to the list.listValue

      listKey and listValue are optional, and if not provided, the list item is used

      Parameters:
        `selectedList` - the name of the action property that contains the list of selected items or single item if its not an array or list
        `list` - the name of the action property that contains the list of selectable items
        `listKey` - an ognl expression that is exaluated relative to the list item to use as the key of the ListEntry
        `listValue` - an ognl expression that is exaluated relative to the list item to use as the value of the ListEntry
      Returns:
        a List of ListEntry

    - #### toInt

          public int toInt(long aLong)

    - #### toLong

          public long toLong(int anInt)

    - #### toLong

          public long toLong(String aLong)

    - #### toString

          public String toString(long aLong)

    - #### toString

          public String toString(int anInt)

    - #### toStringSafe

          public String toStringSafe(Object obj)

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