<jsp:attribute>
The jsp:attribute element allows you to define the value of a tag attribute in the body of an XML element instead of in the value of an XML attribute.
JSP Syntax
<jsp:attribute name="attributeName" [ trim= "true | false" ] />
XML Syntax
Examples
The following template page uses jsp:attribute, which uses the output of fmt:message to set the value of the value attribute of tt:parameter:
... <tt:screen id="/bookcatalog"> <tt:parameter name="title" direct="true"> <jsp:attribute name="value" > <fmt:message key="TitleBookCatalog"/> </jsp:attribute> </tt:parameter> ... </tt:screen> ...
Description
The jsp:attribute standard action has two uses:
- It allows the page author to define the value of an action attribute in the body of an XML element instead of in the value of an XML attribute.
- It allows the page author to specify the attributes of an element dynamically generated by the
jsp:elementaction, which can only appear as a subelement of a standard or custom action.
All JSP standard actions and custom actions can contain a jsp:attribute standard element as a substitute for any of its attributes. One use case in which jsp:attribute is particularly helpful is where the value of an attribute is the result of a multi-line expression, which would not fit in the value of an attribute in the start tag of the action.
If an action contains any jsp:attribute elements and the action also has a body, it must use the jsp:body tag to represent the body. The body of jsp:attribute is restricted according to the type of attribute being specified:
- For simple attributes that do not accept an EL expression, the body can contain only static text.
- For fragment attributes, the body must not contain any scripting elements.
Attributes
name="attributeName"- Identifies which tag attribute is being specified. When used with jsp:element, this attribute specifies the name of the attribute to be included in the generated element.
- If the
jsp:attributetag is not being used withjsp:elementand the action does not accept dynamic attributes, the name must match the name of an attribute for the action being invoked, as declared in the Tag Library Descriptor for a custom action, or as specified for a standard action. If it doesn't match, a translation error results.- If the
jsp:attributeelement is being used with ajsp:elementtag, a translation error results if both an XML element attribute and ajsp:attributeelement are used to specify the value for the same attribute.- The value of name can be a
QName. If so, a translation error must occur if the prefix does not match that of the action it applies to, unless the action supports dynamic attributes or the action isjsp:element. - If the
- Identifies which tag attribute is being specified. When used with jsp:element, this attribute specifies the name of the attribute to be included in the generated element.
trim= "true| false"
- The optional trim attribute determines whether or not whitespace appearing at the beginning and end of the element body should be discarded. By default, the leading and trailing whitespace (including spaces, carriage returns, line feeds, and tabs) is discarded. The whitespace is trimmed when the JSP page is translated. If a body contains a custom tag that produces leading or trailing whitespace, that whitespace is preserved regardless of the value of the trim attribute.
- The optional trim attribute determines whether or not whitespace appearing at the beginning and end of the element body should be discarded. By default, the leading and trailing whitespace (including spaces, carriage returns, line feeds, and tabs) is discarded. The whitespace is trimmed when the JSP page is translated. If a body contains a custom tag that produces leading or trailing whitespace, that whitespace is preserved regardless of the value of the trim attribute.
