org.apache.struts2.components

## Class Set

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

-     public class Set
      extends ContextBean

  The set tag assigns a value to a variable in a specified scope. It is useful when you wish to assign a variable to a complex expression and then simply reference that variable each time rather than the complex expression. This is useful in both cases: when the complex expression takes time (performance improvement) or is hard to read (code readability improvement).

  If the value parameter is omitted, the String to which the body evaluates is set as value for the scoped variable.

  The scopes available are as follows:

  - application - the value will be set in application scope according to servlet spec. using the name as its key
  - session - the value will be set in session scope according to servlet spec. using the name as key
  - request - the value will be set in request scope according to servlet spec. using the name as key
  - page - the value will be set in page scope according to servlet spec. using the name as key
  - action - the value will be set in the request scope and Struts' action context using the name as key

  NOTE:
  If no scope is specified, it will default to action scope.

  Parameters

  - var* (String): The name of the new variable that is assigned the value of value
  - value (Object): The value that is assigned to the variable named name
  - scope (String): The scope in which to assign the variable. Can be application, session, request, page, or action. By default it is action.
  - Note: With the action scope, the variable is also assigned to the page scope.

  Examples

       <s:set var="personName" value="person.name"/>
       Hello, <s:property value="#personName"/>

       <s:set var="janesName">Jane Doe</s:set>
       <s:property value="#janesName"/>

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected String` | `scope`
    `protected boolean` | `trimBody`
    `protected String` | `value`

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

      `var`

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

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

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Set(ValueStack stack)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `end(Writer writer, String body)` Callback for the end tag of this component.
    `void` | `setScope(String scope)`
    `void` | `setTrimBody(boolean trimBody)`
    `void` | `setValue(String value)`
    `void` | `setVar(String var)`
    `boolean` | `usesBody()` Overwrite to set if body should be used.

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

      `getVar, putInContext`

    - ### 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, setActionMapper, setDevMode, setEscapeHtmlBody, setNotExcludedAcceptedPatterns, setPerformClearTagStateForTagPoolingServers, setThrowExceptionsOnELFailure, setUrlHelper, start, stripExpression, toString`

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

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

- - ### Field Detail

    - #### scope

          protected String scope

    - #### value

          protected String value

    - #### trimBody

          protected boolean trimBody

  - ### Constructor Detail

    - #### Set

          public Set(ValueStack stack)

  - ### Method Detail

    - #### 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

    - #### setVar

          public void setVar(String var)

      Overrides:
        `setVar` in class `ContextBean`

    - #### setScope

          public void setScope(String scope)

    - #### setValue

          public void setValue(String value)

    - #### setTrimBody

          public void setTrimBody(boolean trimBody)

    - #### usesBody

          public boolean usesBody()

      Description copied from class: `Component`
      Overwrite to set if body should be used.
      Overrides:
        `usesBody` in class `Component`
      Returns:
        always false for this component.

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