Stripes Tag Library
Tag label
Label tag that can look up localized field labels and render differently when the
labelled field is in error. While the label field is usually used to generated form
field labels, it can be used to generate HTML label tags with arbitrary localized or
non-localized values.
It is important to understand the relationship between the name and
for attributes of the stripes:label tag. The for attribute
is used directly to generated the for attribute of the generated HTML
label tag, and as such should correspond to the HTML id attribute
of the input tag for which it is a label. If the name attribute is omitted
then the value of the for attribute will also be used as the name
attribute.
The value of the label is set by searching for a non-null value in the following
order:
- resource:
{actionFQN}.{name}
- resource:
{actionPath}.{name}
(deprecated)
- resource:
{name}
- The body of the label tag
- A warning message telling you to supply a label value somewhere!
In the case of indexed or mapped form fields (e.g. foo[3].bar) the
indexing and mapping will be removed from the name prior to using it to lookup
labels (e.g. foo.bar). This is done to remain consistent with the way
field names are looked up for error messages.
It should be noted that in cases where a form field and HTML control are
one-to-one (e.g. text, password, select) the name of the label will usually equal
the name of the control. However, this need not be the case. You may use any value
for the name of the label, but the label will only perform error rendering
correctly if the name is equal to the name of the form field being labelled. To
illustrate this point consider the following example:
<th>
<stripes:label for="bug.status"/>:
</th>
<td>
<c:forEach var="status" items="<%=Status.values()%>">
<stripes:radio id="bug.status.${stripes:enumName(status)}"
name="bug.status"
value="${stripes:enumName(status)}"/>
<stripes:label for="bug.status.${stripes:enumName(status)}">
${stripes:enumName(status)}
</stripes:label>
</c:forEach>
</td>
The above example uses one label tag at the top (with for="bug.status") that
labels a row in the table and will display differently when the bug.status field
is in error. It then employs a label tag for each radio button. These are bound to the
individual radio buttons (clicking on the label will select the appropriate radio button),
and default to the name of the enum value if a localized name isn't found. Since these
labels do not match the field name exactly, they will not render differently when the
field is in error.
Tag Information |
Tag Class | net.sourceforge.stripes.tag.InputLabelTag |
TagExtraInfo Class | None |
Body Content | JSP |
Display Name | label |
Attributes |
Name | Required | Request-time | Type | Description |
name | false | true | java.lang.String |
The name of the field being labelled (or of the label if it is not specific to a
field) if the name of the field is not the same as the HTML id of the field. If the
name and id are the same, the for attribute should be used alone.
|
for | false | true | java.lang.String |
The HTML id of the field/control being labelled. If the name attribute is
omitted, the value of this attribute will also be used as the name.
|
accesskey | false | true | java.lang.String | Keyboard shortcut to access the element. (HTML Pass-through) |
class | false | true | java.lang.String | The CSS class to be applied to the element. (HTML Pass-through) |
dir | false | true | java.lang.String | Text direction. (HTML Pass-through) |
id | false | true | java.lang.String | A unique identifier for the HTML tag on the page. (HTML Pass-through) |
lang | false | true | java.lang.String | The language code of the element. (HTML Pass-through) |
onblur | false | true | java.lang.String | Scripting code run when the element loses focus. (HTML Pass-through) |
onchange | false | true | java.lang.String | Scripting code run when the element changes. (HTML Pass-through) |
onclick | false | true | java.lang.String | Scripting code run on each mouse click. (HTML Pass-through) |
ondblclick | false | true | java.lang.String | Scripting code run on a double-click of the mouse. (HTML Pass-through) |
onfocus | false | true | java.lang.String | Scripting code run when the element acquires focus. (HTML Pass-through) |
onkeydown | false | true | java.lang.String | Scripting code run when a key is depressed. (HTML Pass-through) |
onkeypress | false | true | java.lang.String | Scripting code run when a key is pressed and released. (HTML Pass-through) |
onkeyup | false | true | java.lang.String | Scripting code run when a key is released. (HTML Pass-through) |
onmousedown | false | true | java.lang.String | Scripting code run when a mouse button is depressed. (HTML Pass-through) |
onmousemove | false | true | java.lang.String | Scripting code run when the mouse pointer is moved. (HTML Pass-through) |
onmouseout | false | true | java.lang.String | Scripting code run when the mouse pointer moves out of the element. (HTML Pass-through) |
onmouseover | false | true | java.lang.String | Scripting code run when the mouse pointer moves over the element. (HTML Pass-through) |
onmouseup | false | true | java.lang.String | Scripting code run when a mouse button is released. (HTML Pass-through) |
onselect | false | true | java.lang.String | Scripting code run when an element is selected. (HTML Pass-through) |
style | false | true | java.lang.String | Inline CSS style fragment that applies to the element (HTML Pass-through) |
tabindex | false | true | java.lang.String | The tab order of the element. (HTML Pass-through) |
title | false | true | java.lang.String | Tool-tip text for the element. (HTML Pass-through) |
Variables |
No Variables Defined. |
Output Generated by
Tag Library Documentation Generator.
Java, JSP, and JavaServer Pages are trademarks or
registered trademarks of Sun Microsystems, Inc. in the US and other
countries. Copyright 2002-4 Sun Microsystems, Inc.
4150 Network Circle
Santa Clara, CA 95054, U.S.A.
All Rights Reserved.