Here's how to use each of the tags provided by the "Input" tag library. Syntax statements use the style of Sun's JSP Syntax Card.
<input:text name="fieldName"
[ default="defaultValue" ]
[ attributes="<%= attributeMap %>" ] />
The <input:text> tag displays an HTML
<input type="text" ... > element. The element's
name in the HTML will be fieldName. Additionally, the
element's value will be drawn from the fieldName parameter
in the current ServletRequest if it exists, or from
defaultValue if it does not (as long as default
is given a value).
Any key/value pairs in the attributeMap Map provided will be
used as attribute/value pairs in the HTML
<input type="text" ... > element. For instance,
the key/value pair "size" -> "50" will show up as
<input type="text" size="50" ... >
<input:textarea
name="fieldName"
[ default="defaultValue" ]
[ attributes="<%= attributeMap %>" ] />
The <input:textarea> tag displays an HTML
<textarea> element and, potentially, its body too.
The element's name in the HTML will be fieldName.
Additionally, the element's body (its logical "value") will be drawn from
the fieldName parameter in the current
ServletRequest if it exists, or from defaultValue
if it does not (as long as default is given a value).
This tag does not take a body. It may produce a body in the underlying HTML if appropriate, but all of the logic is encapsulated into this single tag in order to make it easier to use.
Any key/value pairs in the attributeMap Map provided will be
used as attribute/value pairs in the HTML
<textarea> element. For instance,
the key/value pair "rows" -> "40" will show us as
<textarea rows="40" ... >
<input:select
name="fieldName"
options="<%= optionsMap %>"
[ default="defaultValue" ]>
[ attributes="<%= attributeMap %>" ] />
The <input:select> tag displays an HTML
<select> element and its subordinate <options>.
The element's name in the HTML will be fieldName.
A list of <option> tags will come from the optionsMap
Map, and each individual option will be marked selected if it
corresponds to the fieldName parameter
in the current ServletRequest if it exists, or from
defaultValue if it does not (as long as default
is given a value).
This tag does not take a body. It may produce a body in the underlying HTML if appropriate, but all of the logic is encapsulated into this single tag in order to make it easier to use.
Any key/value pairs in the attributeMap Map provided will be
used as attribute/value pairs in the HTML
<select> element. If you wish to use the attribute
<multiple>, you may wish to pass a Map that allows
null values; the HashMap class works nicely.
Sample code for this is:
<% HashMap attr = new HashMap(); %>
<% attr.put("multiple", null); %>
<input:select ... attributes="<%= attr %>" />
You might find that code like this is easier to read and maintain in bulk than tags with multiple attribute/value pairs.
This tag supports multiple selections if it retrieves them from the
ServletRequest and the box is labelled as a multiple
selection box (i.e., attributeMap contains multiple
as a key). If there are multiple selections in the ServletRequest
and the <select> box is not labelled multiple,
the selections are thrown away (instead of choosing one at random).
<input:radio
name="buttonGroupName"
value="buttonValue"
[ default="defaultValue" ]
[ attributes="<%= attributeMap %>" ] />
The <input:radio> tag displays a single HTML
<input type="radio" ...>. To display all buttons in
a radio group, you need to use this tag multiple times with different
values.
The element's name in the HTML will be buttonGroupName. (You
can have as many buttons with the same buttonGroupName as you
need.)
Additionally, each particular button will be marked checked
if its buttonValue equals the value of
the fieldName parameter in the current
ServletRequest if it exists, or the defaultValue
if it does not (as long as default is given a value).
Any key/value pairs in the attributeMap Map provided will be
used as attribute/value pairs in the HTML
<input type="radio" ...> element. For instance,
the key/value pair "disabled" -> null will show us as
<input type="radio" disabled ... >
<input:checkbox
name="buttonGroupName"
value="buttonValue"
[ default="defaultValue" ]
[ defaults="<%= defaultStringArray %>" ]
[ attributes="<%= attributeMap %>" ] />
The <input:checkbox> tag displays a single HTML
<input type="checkbox" ...>. To display all buttons in
a checkbox group, you need to use this tag multiple times with different
values.
The element's name in the HTML will be buttonGroupName. (You
can have as many checkboxes with the same buttonGroupName as
you need.)
Additionally, this checkbox will be marked as checked if the
tag believes it ought to be checked. The rules are as follows: if
the current ServletRequest is empty (i.e., contains no
parameters), then we combine the default and defaults
String and String[] (respectively), and if the
current checkbox's buttonValue is in that list of defaults,
then the tag marks the checkbox as checked. Otherwise, the tag
marks the checkbox as checked if and only if the box's
buttonValue is in the list of values associated with
buttonGroupName in the current ServletRequest.
Note: The rules for determining whether a checkbox is checked or
not are different than the rules for other input or selection types.
This is the result of underlying differences between the way CGI
handles checkboxes and other fields. If a text box is empty, browsers
assert, via the POST or GET to the server, an empty value; however,
if all checkboxes for a given checkbox group are unchecked, the browser
doesn't include any information about the checkbox group in its POST or
GET. Thus, if this tag simply looked toward the parameter in the current
ServletRequest, defaults would be restored on the resulting
page--that is, checkboxes wouldn't necessarily stay unchecked.
(As an aside, we'd have to do the same thing with radio buttons, but
browsers don't let users uncheck all radio buttons, and if the default
provides for no buttons to be checked, then there's, tidily enough,
no problem with accepting the default in the case where all buttons
remain unchecked.)
Any key/value pairs in the attributeMap Map provided will be
used as attribute/value pairs in the HTML
<input type="checkbox" ...> element. For instance,
the key/value pair "disabled" -> null will show us as
<input type="checkbox" disabled ... >