This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • set
Skip to end of metadata
Go to start of metadata

Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

Description

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 tag is used with body content, the evaluation of the value parameter is omitted. Instead, 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

Dynamic Attributes Allowed:

false
 

Name

Required

Default

Evaluated

Type

Description

scope false action false String The scope in which to assign the variable. Can be application, session, request, page, or action.
trimBody false true false Boolean Set to false to prevent the default whitespace-trim of this tag's body content
value false false String The value that is assigned to the variable named name
var true false String Name used to reference the value pushed into the Value Stack

Examples

Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<s:set var="personName" value="person.name"/>
Hello, <s:property value="#personName"/>

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

1 Comment

  1. Example 2:

    The string object can be accessed as
    <s:set name="personName" value=" 'TestValue' "/>
    Hello, <s:property value="#personName"/>. How are you?

    This example will print:
    Hello, TestValue. How are you?