43. spring JSP Tag Library

43.1 Introduction

One of the view technologies you can use with the Spring Framework is Java Server Pages (JSPs). To help you implement views using Java Server Pages the Spring Framework provides you with some tags for evaluating errors, setting themes and outputting internationalized messages.

Please note that the various tags generated by this form tag library are compliant with the XHTML-1.0-Strict specification and attendant DTD.

This appendix describes the spring.tld tag library.

43.2 The argument tag

Argument tag based on the JSTL fmt:param tag. The purpose is to support arguments inside the message and theme tags.

Table 43.1. Attributes

AttributeRequired?Runtime Expression?Description
valuefalsetrueThe value of the argument.

43.3 The bind tag

Provides BindStatus object for the given bind path. The HTML escaping flag participates in a page-wide or application-wide setting (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).

Table 43.2. Attributes

AttributeRequired?Runtime Expression?Description
htmlEscapefalsetrueSet HTML escaping for this tag, as boolean value. Overrides the default HTML escaping setting for the current page.
ignoreNestedPathfalsetrueSet whether to ignore a nested path, if any. Default is to not ignore.
pathtruetrueThe path to the bean or bean property to bind status information for. For instance account.name, company.address.zipCode or just employee. The status object will exported to the page scope, specifically for this bean or bean property

43.4 The escapeBody tag

Escapes its enclosed body content, applying HTML escaping and/or JavaScript escaping. The HTML escaping flag participates in a page-wide or application-wide setting (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).

Table 43.3. Attributes

AttributeRequired?Runtime Expression?Description
htmlEscapefalsetrueSet HTML escaping for this tag, as boolean value. Overrides the default HTML escaping setting for the current page.
javaScriptEscapefalsetrueSet JavaScript escaping for this tag, as boolean value. Default is false.

43.5 The eval tag

Evaluates a Spring expression (SpEL) and either prints the result or assigns it to a variable.

Table 43.4. Attributes

AttributeRequired?Runtime Expression?Description
expressiontruetrueThe expression to evaluate.
htmlEscapefalsetrueSet HTML escaping for this tag, as a boolean value. Overrides the default HTML escaping setting for the current page.
javaScriptEscapefalsetrueSet JavaScript escaping for this tag, as a boolean value. Default is false.
scopefalsetrueThe scope for the var. 'application', 'session', 'request' and 'page' scopes are supported. Defaults to page scope. This attribute has no effect unless the var attribute is also defined.
varfalsetrueThe name of the variable to export the evaluation result to. If not specified the evaluation result is converted to a String and written as output.

43.6 The hasBindErrors tag

Provides Errors instance in case of bind errors. The HTML escaping flag participates in a page-wide or application-wide setting (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).

Table 43.5. Attributes

AttributeRequired?Runtime Expression?Description
htmlEscapefalsetrueSet HTML escaping for this tag, as boolean value. Overrides the default HTML escaping setting for the current page.
nametruetrueThe name of the bean in the request, that needs to be inspected for errors. If errors are available for this bean, they will be bound under the 'errors' key.

43.7 The htmlEscape tag

Sets default HTML escape value for the current page. Overrides a "defaultHtmlEscape" context-param in web.xml, if any.

Table 43.6. Attributes

AttributeRequired?Runtime Expression?Description
defaultHtmlEscapetruetrueSet the default value for HTML escaping, to be put into the current PageContext.

43.8 The message tag

Retrieves the message with the given code, or text if code isn’t resolvable. The HTML escaping flag participates in a page-wide or application-wide setting (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).

Table 43.7. Attributes

AttributeRequired?Runtime Expression?Description
argumentsfalsetrueSet optional message arguments for this tag, as a (comma-)delimited String (each String argument can contain JSP EL), an Object array (used as argument array), or a single Object (used as single argument).
argumentSeparatorfalsetrueThe separator character to be used for splitting the arguments string value; defaults to a 'comma' (',').
codefalsetrueThe code (key) to use when looking up the message. If code is not provided, the text attribute will be used.
htmlEscapefalsetrueSet HTML escaping for this tag, as boolean value. Overrides the default HTML escaping setting for the current page.
javaScriptEscapefalsetrueSet JavaScript escaping for this tag, as boolean value. Default is false.
messagefalsetrueA MessageSourceResolvable argument (direct or through JSP EL). Fits nicely when used in conjunction with Spring’s own validation error classes which all implement the MessageSourceResolvable interface. For example, this allows you to iterate over all of the errors in a form, passing each error (using a runtime expression) as the value of this 'message' attribute, thus effecting the easy display of such error messages.
scopefalsetrueThe scope to use when exporting the result to a variable. This attribute is only used when var is also set. Possible values are page, request, session and application.
textfalsetrueDefault text to output when a message for the given code could not be found. If both text and code are not set, the tag will output null.
varfalsetrueThe 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 (i.e. typically directly to the JSP).

43.9 The nestedPath tag

Sets a nested path to be used by the bind tag’s path.

Table 43.8. Attributes

AttributeRequired?Runtime Expression?Description
pathtruetrueSet the path that this tag should apply. E.g. 'customer' to allow bind paths like 'address.street' rather than 'customer.address.street'.

43.10 The param tag

Parameter tag based on the JSTL c:param tag. The sole purpose is to support params inside the url tag.

Table 43.9. Attributes

AttributeRequired?Runtime Expression?Description
nametruetrueThe name of the parameter.
valuefalsetrueThe value of the parameter.

43.11 The theme tag

Retrieves the theme message with the given code, or text if code isn’t resolvable. The HTML escaping flag participates in a page-wide or application-wide setting (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).

Table 43.10. Attributes

AttributeRequired?Runtime Expression?Description
argumentsfalsetrueSet optional message arguments for this tag, as a (comma-)delimited String (each String argument can contain JSP EL), an Object array (used as argument array), or a single Object (used as single argument).
argumentSeparatorfalsetrueThe separator character to be used for splitting the arguments string value; defaults to a 'comma' (',').
codefalsetrueThe code (key) to use when looking up the message. If code is not provided, the text attribute will be used.
htmlEscapefalsetrueSet HTML escaping for this tag, as boolean value. Overrides the default HTML escaping setting for the current page.
javaScriptEscapefalsetrueSet JavaScript escaping for this tag, as boolean value. Default is false.
messagefalsetrueA MessageSourceResolvable argument (direct or through JSP EL).
scopefalsetrueThe scope to use when exporting the result to a variable. This attribute is only used when var is also set. Possible values are page, request, session and application.
textfalsetrueDefault text to output when a message for the given code could not be found. If both text and code are not set, the tag will output null.
varfalsetrueThe 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 (i.e. typically directly to the JSP).

43.12 The transform tag

Provides transformation of variables to Strings, using an appropriate custom PropertyEditor from BindTag (can only be used inside BindTag). The HTML escaping flag participates in a page-wide or application-wide setting (i.e. by HtmlEscapeTag or a 'defaultHtmlEscape' context-param in web.xml).

Table 43.11. Attributes

AttributeRequired?Runtime Expression?Description
htmlEscapefalsetrueSet HTML escaping for this tag, as boolean value. Overrides the default HTML escaping setting for the current page.
scopefalsetrueThe 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.
valuetruetrueThe 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.
varfalsetrueThe 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 (i.e. typically directly to the JSP).

43.13 The url tag

Creates URLs with support for URI template variables, HTML/XML escaping, and Javascript escaping. Modeled after the JSTL c:url tag with backwards compatibility in mind.

Table 43.12. Attributes

AttributeRequired?Runtime Expression?Description
valuetruetrueThe URL to build. This value can include template that are replaced with the URL encoded value of the named parameter. Parameters must be defined using the param tag inside the body of this tag.
contextfalsetrueSpecifies a remote application context path. The default is the current application context path.
varfalsetrueThe name of the variable to export the URL value to. If not specified the URL is written as output.
scopefalsetrueThe scope for the var. 'application', 'session', 'request' and 'page' scopes are supported. Defaults to page scope. This attribute has no effect unless the var attribute is also defined.
htmlEscapefalsetrueSet HTML escaping for this tag, as a boolean value. Overrides the default HTML escaping setting for the current page.
javaScriptEscapefalsetrueSet JavaScript escaping for this tag, as a boolean value. Default is false.
Updated at: 7 months ago
42.8. Further ResourcesTable of content44. spring-form JSP Tag Library