## `spring:transform`

### org.springframework.web.servlet.tags.TransformTag

`spring:transform (since 1.0)`
General information
The `spring:transform` tag provides you with support for transforming properties not contained by a command using PropertyEditors associated with the command. Suppose you have 10 dates you want to let the user choose from, you need to transform the date in the same way you would do, when using the `spring:bind` tag. The `spring:transform` tag provides this support. Note: this tag can only be used inside a `spring:bind` tag!
Attributes
value
The value to transform. This is the actual object you want to have transformed (for instance a Date). Using the PropertyEditor that is currently in use by the `spring:bind` tag.
required: yes
el-support: yes
var
The string to use when binding the result to the page, request, session or application scope. If not specified, the result gets outputted to the writer (directly to the JSP i.e.).
required: no
el-support: yes
scope
The scope to use when exported the result to a variable. This attribute is only used when `var` is also set. Possible values are `page`, `request`, `session` and `application`.
required: no
el-support: yes
htmlEscape
Set HTML escaping for this tag, as boolean value. Overrides the default HTML escaping setting for the current page.
required: no
el-support: yes
Variables
If the `var` argument is specified, the resolved message will be exported to the scope specified by the `scope` argument.
Also have a look at
the `spring:bind` tag, to see in which tag you need to nest this tag
A possible usecase
Consider the following: SimpleFormController that controls `Contract` object Amongst others, the Person object has a `contractType` property Available contract types are `silver`, `gold` and `premium` and they are instance of the enumeration called `ContractType` You want to be able to let the user select the appropriate type of contract In your controller (e.g. SimpleFormController), you have implemented the `referenceData()` method that returns a List of the available contract types under the key `contractTypes` To display the select widget from which the user can select a contract type:
    <form method="post">
        ## bind on the contractType property
        <spring:bind path="contract.contractType">
            ## render the select box
            <select name="<c:out value="${status.expression}"/>">
                ## iterate over all the contract types available
                <c:forEach items="${contractTypes}" var="type">
                    ## transform the contract type using the property editor
                    ## used to create the BindStatus object
                    <spring:transform value="${type}" var="typeString"/>
                    <option
                        ## output the value (databinding will be able to use this!)
                        value="<c:out value="${typeString}"/>
                        ## see if it is selected
                        <c:if test="${status.value == typeString}"/> selected</c:if>>
                        ## you could also use the typeString var for i18n (spring:message)
                        <c:out value="${typeString}"/>
                    </option>
                </c:forEach>
            </select>
        </spring:bind>
    </form>