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).

The set tag accepts body. However the followings need to be take note when using set tag with body

  • body are treated as String and will not be parsed by OGNL
  • body could be scriptlet or JSP tags, the String representation of scriptlet or JSP tags will be used
  • A non-empty will take precedence if there's also a value attribute present, if the body is empty, then the value attribute will be used

Parameters

Name

Required

Default

Type

Description

name true   String The name of the new variable that is assigned the value of value
scope false action String The scope in which to assign the variable. Can be application, session, request, page, or action.
value false   Object/String The value that is assigned to the variable named name
id false   Object/String id for referencing element. For UI and form tags it will be used as HTML id attribute

Examples

<ww:set name="personName" value="person.name"/>
Hello, <ww:property value="%{#personName}"/>. How are you?

<ww:set name="personName">
  <ww:property value="%{'some string'}" />
</ww:set>
Hello, <ww:property value="%{#personName}"/>. How are you?

<ww:set name="personName">
   <c:set value="${person.name}" />
</ww:set>
Hello, <ww:property value="%{#personName}"/>. How are you?