The Set Tag

During transformation, is may be desirable occasionally to change or set the value of a bean variable. One use case would be to create a short cut for a verbose expression that is commonly used, e.g. shortcut for x.foo.foo2.foo3.foo4.foo5. While one can define such a variable in the beans map prior to transformation, the "set" tag allows one to do so during transformation.

Use the optional "display" attribute to display the contents of the cell, if any.

Attributes

  • The "set" tag supports all base tag attributes.
  • var: String Required. The name of the variable in the beans map to set to a new value. If there is no such variable, it is created. If there already is such a variable, its value is overwritten.
  • value: Object Required. The new value of the variable.
  • display: RichTextString Optional. This determines the contents of the cell. The default is blank.

Example

In this example, a relatively complicated expression employees[3].catchPhrase is assigned to a new variable bugsCatchPhrase, a new value is assigned to x, and a new numeric value is assigned to y. Subsequently, each variable is displayed. The tag in C2 is cut off; the full value of the cell is <jt:set var="bugsCatchPhrase" value="${employees[3].catchPhrase}" display="${bugsCatchPhrase}"/>.

Set Template

After transformation, the new variables have their values. Notice how ${1} was used to assign a numeric value to a variable; content outside of ${} is interpreted as text.

Set Result

The new values of variables are available in cells that are processed after the cell in which the "set" tag was evaluated.