The HTML Tag Library Tags

 < Day Day Up > 



The following table lists each of the tags in the HTML Tag Library and a short description of each tag’s purpose.

Tag

Description

base

Generates an HTML <base> tag with its href attribute set to the absolute URL of the enclosing JSP.

button

Generates an HTML <input type=“button”> tag.

cancel

Generates an HTML <input type=“submit”> tag that, when executed, causes Struts’ Cancel feature to be triggered.

checkbox

Generates an HTML <input type=“checkbox”> tag populated with data from a specified object.

errors

Displays a set of error messages stored as an org.apache.struts.action.ActionErrors object, a String, or a String array in request scope.

file

Generates an HTML <input type=“file”> tag populated with data from a specified object.

form

Generates an HTML <form> tag tied to an Action object and its corresponding Form Bean from the struts-config.xml file.

frame

Generates an HTML <frame> tag.

hidden

Generates an HTML <input type=“hidden”> tag populated with data from a specified object.

html

Generates an HTML <html> tag with language attributes set to the current user’s locale.

image

Generates an HTML <input type=“image”> tag.

img

Generates an HTML <img> tag

javascript

Generates client-side JavaScript validation code for validations defined in the Validator framework’s validation.xml file.

link

Generates an HTML hyperlink <a> tag whose URL is composed by specifying a base URL and optionally specifying an anchor and/or query string parameters to add to the URL.

messages

Displays a set of messages stored as an org.apache.struts.action.ActionErrors object, an org.apache.struts.action.ActionMessages object, a String, or a String array in request scope.

multibox

Generates an HTML <input type=“checkbox”> tag whose checked status is based on whether or not a specified value matches one of the values in a specified array of values.

option

Generates an HTML <option> tag.

options

Generates a set of HTML <option> tags for each element in a collection.

optionsCollection

Generates a set of HTML <option> tags for each element in a collection.

password

Generates an HTML <input type=“password”> tag populated with data from a specified object.

radio

Generates an HTML <input type=“radio”> tag populated with data from a specified object.

reset

Generates an HTML <input type=“reset”> tag.

rewrite

Generates a URL by specifying a base URL and optionally specifying an anchor and/or query string parameters to add to the URL.

select

Generates an HTML <select> tag.

submit

Generates an HTML <input type=“submit”> tag.

text

Generates an HTML <input type=“text”> tag populated with data from a specified object.

textarea

Generates an HTML <textarea> tag populated with data from a specified object.

xhtml

Instructs the rest of the tags in the HTML Tag Library to generate their output as XHTML instead of HTML.

The remainder of this chapter discusses each tag in detail, including a complete description of the tag, a table listing each of the tag’s attributes, and a usage example for the tag. In the tables that describe each tag’s attributes, pay special attention to the Required and Accepts Scriptlet columns.

The Required column denotes whether or not the given attribute is required when using the tag. If an attribute is required and you do not specify it when using the tag, the tag will throw a javax.servlet.jsp.JspException at run time. Note that you can declare an error page in your JSP with a page directive to capture any JspExceptions that might be thrown, as shown here:

<%@ page errorPage="error.jsp" %>

If an exception occurs, the page specified by the errorPage attribute will be internally redirected to display an error page.

The Accepts Scriptlet column denotes whether or not the given attribute’s value can be specified with a JSP scriptlet. If a JSP scriptlet is used to specify an attribute value, the scriptlet must comprise the complete value, quote (“) to quote (”), as shown here.

Correct:

<html:checkbox property="<%=prop%>">

Incorrect:

<html:checkbox property="<%=result%>-checked">

Notice in the incorrect example that “-checked” is used as part of the value for the property attribute following the scriptlet. This is invalid because there are extra characters between the end of the scriptlet and the ending quote.

A corrected version of the incorrect example follows:

<html:checkbox property="<%=result + "-checked"%>"/>

The concatenation of “-checked” is now part of the scriptlet and the scriptlet comprises the complete value for the attribute.

One other point: Several of the tags have a set of tag attributes in common, such as onclick, onmousedown, and onkeypress. Rather than repeat the description for these common attributes numerous times, they are described once, at the end of this chapter in the “Common Tag Attributes” section. The Description column in each tag’s table of attributes refers you to the “Common Tag Attributes” section for any of the common tag attributes that the tag has in its set of tag attributes.

The base Tag

The base tag is used to generate an HTML <base> tag with its href attribute set to the absolute URL of the enclosing JSP. Note that this tag must be nested inside of an HTML <head> tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

server

Specifies the server name to use when generating the corresponding HTML tag’s href attribute.

Yes

No

target

Same as the corresponding HTML tag’s attribute with the same name.Specifies the frame or window target in which links will be opened.

Yes

No

Example Usage

The following snippet shows the basic usage of the base tag:

<html:html> <head>   <title></title>   <html:base/> </head>

Remember that this tag must be enclosed by opening and closing HTML <head> tags.

The button Tag

The button tag is used to generate an HTML <input type=“button”> tag. Note that this tag must be nested inside of this library’s form tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index (e.g., “property[x]”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Same as the corresponding HTML tag’s name attribute.Specifies the name that will be associated with this control.

Yes

Yes

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that this control will be populated with.This value will be used for the button’s label. If not specified, this tag will attempt to use its body content as the value for the button’s label.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the button tag:

<html:button property="direction" value="Next Page"/> 

The value specified with the value attribute will be used for the button’s label. Alternatively, you can specify the button’s label value by nesting a string between opening and closing button tags, as shown here:

<html:button>Next Page</html:button>

The cancel Tag

Struts has a built-in Cancel feature that will cause it to bypass calling a Form Bean’s validate( ) method if a request parameter named “org.apache.struts.taglib.html.CANCEL” is present in an incoming request. Additionally, Action objects can call an isCancelled( ) method to determine whether or not a request was cancelled. The cancel tag generates an HTML <input type=“submit”> tag with its name attribute set to “org.apache.struts.taglib.html.CANCEL” so that, when executed, Struts’ Cancel feature will be triggered. Note that this tag must be nested inside of the form tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Same as the corresponding HTML tag’s name attribute.Specifies the name that will be associated with this control.Caution: If you set this attribute to a value other than its default, Struts’ Cancel feature will not be triggered.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that this control will be populated with.This value will be used for the button’s label. If not specified, this tag will attempt to use its body content as the value for the button’s label.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the cancel tag:

<html:cancel value="Cancel Update"/>

The value specified with the value attribute will be used for the button’s label. Alternatively, you can specify the button’s label value by nesting a string between opening and closing cancel tags, as shown here:

<html:cancel>Cancel Update</html:cancel>

The checkbox Tag

The checkbox tag is used to generate an HTML <input type=“checkbox”> tag populated with data from a specified object. Note that this tag must be nested inside of this library’s form tag. Additionally, the underlying Form Bean field associated with this control must be of primitive type boolean or of type Boolean and the Form Bean’s reset( ) method must include a statement that resets the field to false.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index. (e.g., “name[x].property”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will be used to populate this control with data.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Specifies the value to set the corresponding HTML tag’s name attribute to.Additionally, this attribute is used to specify the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used to populate this control. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

Yes

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that the control will be populated with.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the checkbox tag:

<html:form action="/register"> Subscribe to mailing list: <html:checkbox property="subscribe"/><br> <html:submit/> </html:form>

This tag will look up the Form Bean associated with the Action specified by the form tag’s action attribute and then call the getter method for the field specified by this tag’s property attribute. The field’s value will then be used to populate the HTML control with data.

The errors Tag

The errors tag is used to display a set of error messages stored as an org.apache.struts.action.ActionErrors object, a String, or a String array in request scope. This tag will take the stored error messages and iterate over them, displaying them in succession. Additionally, this tag uses the values for the following table of keys from Strut’s ApplicationResources.properties file to format the messages.

Key

Purpose

errors.header

Text that will be output before the list of error messages.

errors.footer

Text that will be output after the list of error messages.

errors.prefix

Text that will be output before each error message.

errors.suffix

Text that will be output after each error message.

Attributes

Attribute

Description

AcceptsScriptlet

Required

bundle

Specifies the logical name of a resource bundle that will be used when looking up error keys.

Yes

No

locale

Specifies the key for a java.util.Locale instance stored as a session attribute that will be used when looking up error keys.

Yes

No

name

Specifies the key (in any scope) under which the errors to be displayed are stored. If not specified, the default org.apache.struts.Globals.ERROR_KEY key will be used.

Yes

No

property

Specifies the field for which errors will be displayed. If not specified, all errors will be displayed.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the errors tag:

<html:errors/>

This example will display all the errors currently stored. If you want to limit the errors that are displayed to a specific property, you can specify that property when using the errors tag, as shown here:

<html:errors property="username"/> 

In this case, only the errors associated with the property specified by the property attribute will be displayed.

The file Tag

The file tag is used to generate an HTML <input type=“file”> tag populated with data from a specified object. Note that this tag must be nested inside of the form tag. Additionally, the enclosing form tag must specify its HTTP method as being POST and its encoding type as being multipart/form-data, as shown here:

<html:form method="POST" enctype="multipart/form-data"> … </html:form>

Attributes

Attribute

Description

Accepts Scriptlet

Required

accept

Same as the corresponding HTML tag’s attribute with the same name. Specifies a comma-delimited list of content types that the server you submit the enclosing form to knows how to process. Browsers can use this list to limit the set of files made available for selection.

Yes

No

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index (e.g., “name[x].property”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

maxlength

Same as the corresponding HTML tag’s attribute with the same name.Specifies the maximum number of characters that this control will accept.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will be used to populate this control with data.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Specifies the value to which the corresponding HTML tag’s name attribute is set.Additionally, this attribute is used to specify the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used to populate this control. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

Yes

size

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of characters that will be visible in the control.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that is used to populate the control.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the file tag:

<html:form method="POST"          enctype="multipart/form-data"       action="/attachFile"> Upload File: <html:file property="uploadFile"/><br> <html:submit/> </html:form>

This tag will look up the Form Bean associated with the Action specified by the form tag’s action attribute and then call the getter method for the field specified by this tag’s property attribute. The field’s value will then be used to populate the HTML control with data.

The form Tag

The form tag is used to generate an HTML <form> tag tied to an Action and its corresponding Form Bean from the struts-config.xml file. The Action’s Form Bean will be used by other tags from this library to populate them with data when they are nested inside this tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

action

Specifies the logical name of an Action, defined in the struts-config.xml file, whose path will be used to define the corresponding HTML tag’s attribute with the same name.

Yes

Yes

enctype

Same as the corresponding HTML tag’s attribute with the same name.Specifies the encoding to be used when submitting this form if the POST method is used. This must be set to “multipart/ form-data” if you are using the file tag to upload files.

Yes

No

focus

Specifies the name of a field inside this form that initial focus will be assigned to using JavaScript.

Yes

No

focusIndex

Specifies an index to be used if the field specified with the focus attribute is a field array such as a radio button group.

Yes

No

method

Same as the corresponding HTML tag’s attribute with the same name.Specifies the HTTP method that will be used when submitting this form (i.e., GET or POST).

Yes

No

name

DeprecatedUse the action attribute instead.

Yes

No

onreset

Same as the corresponding HTML tag’s attribute with the same name.Specifies the JavaScript code to execute when this form is reset.

Yes

No

onsubmit

Same as the corresponding HTML tag’s attribute with the same name.Specifies the JavaScript code to execute when this form is submitted.

Yes

No

scope

DeprecatedUse the action attribute instead.

Yes

No

scriptLanguage

Accepts “false” to denote that the language attribute of the <focus> tag generated by this tag’s focus attribute should be omitted.Note that the generated <focus> tag’s language attribute is omitted regardless when the tags in this library are in XHTML mode.

Yes

No

style

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

target

Same as the corresponding HTML tag’s attribute with the same name.Specifies the frame or window target in which this form will be submitted.

Yes

No

type

DeprecatedUse the action attribute instead.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the form tag:

<html:form action="/logon"> UserName: <html:text property="username"/><br> Password: <html:password property="password"/><br> <html:submit/> </html:form>

The Form Bean associated with the Action specified by the action attribute will be used for populating the nested HTML controls inside the opening and closing form tags.

The frame Tag

The frame tag is used to generate an HTML <frame> tag. The frame’s URL is composed by specifying a base URL and optionally specifying an anchor and/or query string parameters to add to the URL.

There are four ways to specify the base URL:

  • You can use the action attribute to specify the name of an Action from the Struts configuration file whose URL will be used.

  • You can use the forward attribute to specify the name of a forward from the Struts configuration file whose URL will be used.

  • You can use the href attribute to specify an absolute URL, including protocol (e.g., http://www.yahoo.com/).

  • You can use the page attribute to specify an application-relative URL.

In addition to specifying the base URL, you have two options for specifying query string parameters to add to the base URL:

  • You can use the paramId attribute in conjunction with the paramName attribute, and optionally the paramProperty attribute, to specify a single parameter.

  • You can use the name attribute, either alone or in tandem with the property attribute, to specify a java.util.Map object that will be used to add several parameters.

Attributes

Attribute

Description

Accepts Scriptlet

Required

action

Specifies the name of an Action, from the Action Mappings section of the Struts configuration file, that contains the URL for this frame.

Yes

No

anchor

Specifies the anchor (e.g., “#bottom”) to be added to the URL for this frame. This value must be specified without the leading hash (#) character.

Yes

No

forward

Specifies the name of a forward, from the Global Forwards Configuration section of the Struts configuration file, that contains the URL for this frame.

Yes

No

frameborder

Same as the corresponding HTML tag’s attribute with the same name.Specifies the border size for this frame (0 for no border).

Yes

No

frameName

Same as the corresponding HTML tag’s name attribute.Specifies the logical name to give the frame.

Yes

No

href

Specifies the absolute URL, including protocol (e.g., http://www.yahoo.com), for this frame.

Yes

No

longdesc

Same as the corresponding HTML tag’s attribute with the same name.Specifies the URL for a long description of the frame that supplements the short description provided by the title attribute.

Yes

No

marginheight

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of pixels that will be placed between this frame’s contents and its top and bottom margins.

Yes

No

marginwidth

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of pixels that will be placed between this frame’s contents and its left and right margins.

Yes

No

name

Specifies the name of the java.util.Map object whose elements are added as query string parameters to the URL for this frame. If the property attribute is also specified, one of the fields of the object defined by this attribute will have its getter method called to return the java.util.Map object whose elements are added as query string parameters to the URL for this frame.

Yes

No

noresize

Same as the corresponding HTML tag’s attribute with the same name.Accepts “true” to denote that this frame will not be resizable.

Yes

No

page

Specifies the application-relative URL (starts with a leading slash, /) for this frame.

Yes

No

paramId

Specifies the name of a single parameter to add to the URL for this frame.

Yes

No

paramName

Specifies the name of an object whose value will be used as the value for the parameter specified with the paramId attribute. If the property attribute is also specified, one of the fields of the object defined by this attribute will have its getter method called to return an object whose value will be used as the value for the parameter specified with the paramId attribute.

Yes

No

paramProperty

Specifies the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used as the value for the parameter specified with the paramId attribute.

Yes

No

paramScope

Specifies the scope (application, page, request, or session) to look in for the object specified by the paramName attribute. If not specified, each scope will be searched, in this order: page, request, session, and then application.

Yes

No

property

Specifies the field of the object specified by the name attribute whose getter method will be called to return the java.util.Map object whose elements are added as query string parameters to the URL for this frame.

Yes

No

scope

Specifies the scope (application, page, request, or session) to look in for the object specified by the name attribute. If not specified, each scope will be searched, in this order: page, request, session, and then application.

Yes

No

scrolling

Same as the corresponding HTML tag’s attribute with the same name.Specifies whether or not this frame is scrollable. Specify “yes” to have scroll bars unconditionally, “no” to never have scroll bars, or “auto” to have scroll bars automatically based on how much content is in the frame.

Yes

No

style

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

transaction

Accepts “true” or “false” to denote whether or not the current transaction token is included in the URL for this frame.

Yes

No

Example Usage

There are a few different ways to use the frame tag. The first way, shown here, uses the href attribute to specify an absolute URL for the frame:

<html:frame href="http://www.yahoo.com/"/> 

The following example adds to the first example by specifying a single query string parameter to add to the base URL specified by the href attribute:

<html:frame href="http://www.yahoo.com/"       param       paramName="queryObj"/>

This example takes the base URL specified by the href attribute and appends the query string parameter specified by the paramId and paramName attributes and composes a URL for the frame.

Another way to use the frame tag is shown here:

<html:frame page="/search.jsp" name="params"/>

This example uses the page attribute to specify an application-relative base URL and uses the name attribute to specify a java.util.Map object whose entries are added to the URL as query string parameters.

The hidden Tag

The hidden tag is used to generate an HTML <input type=“hidden”> tag populated with data from a specified object. Note that this tag must be nested inside of the form tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index (e.g., “name[x].property”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will be used to populate this control with data.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Specifies the value to which the corresponding HTML tag’s name attribute is set.Additionally, this attribute is used to specify the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used to populate this control. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

Yes

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that this control will be populated with.

Yes

No

write

Accepts “true” to denote that this control’s value will also be written out to the page so that it is visible.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the hidden tag:

<html:form action="/search"> <html:hidden property="lastId"/> <html:submit/> </html:form> 

This tag will look up the Form Bean associated with the Action specified by the form tag’s action attribute and then call the getter method for the field specified by this tag’s property attribute. The field’s value will then be used to populate the HTML control with data.

The html Tag

The html tag is used to generate an HTML <html> tag with language attributes set to the current user’s locale. Additionally, you can use this tag to instruct the rest of the tags in the HTML Tag Library to generate their output as XHTML instead of HTML. More information on XHTML can be found at http://www.w3.org/TR/xhtml1/.

Attributes

Attribute

Description

Accepts Scriptlet

Required

locale

Accepts “true” to denote that a java.util.Locale object, set to the current request’s “AcceptLanguage” HTTP header, will be placed into the session. If a session does not exist, one will be created upon this tag storing the Locale object.

Yes

No

xhtml

Accepts “true” to denote that the rest of the tags in the HTML Tag Library will generate their output as XHTML instead of HTML.

Yes

No

Example Usage

The following snippet shows the basic usage of the html tag:

<html:html/>

If you want the HTML Tag Library’s tags to generate XHTML instead of HTML, use the html tag as shown here:

<html:html xhtml="true"/>

The image Tag

The image tag is used to generate an HTML <input type=“image”> tag. Note that this tag must be nested inside of a form tag.

There are two ways you can use the image tag, as listed here and shown later in the “Example Usage” section:

  • You can use the page or pageKey attribute to specify a module-relative URL that will be used as the generated HTML tag’s src attribute.

  • You can use the src or srcKey attribute to specify a URL that will be used as the generated HTML tag’s src attribute.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

align

Same as the corresponding HTML tag’s attribute with the same name.Specifies how the image will be aligned (i.e., left, right, top, bottom, and so on).

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

border

Same as the corresponding HTML tag’s attribute with the same name.Specifies the width of the border surrounding the image.

Yes

No

bundle

Specifies the logical name of a resource bundle that will be used when looking up message keys specified by other attributes of this tag (i.e., pageKey and srcKey).

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index (e.g., “property[x]”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

locale

Specifies the key for a java.util.Locale instance stored as a session attribute that will be used when looking up message keys specified by other attributes of this tag (i.e., pageKey and srcKey).

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

page

Specifies a module-relative URL for this button’s image.

Yes

No

pageKey

Specifies a key from Struts’ ApplicationResources.properties file whose value will be used to set the corresponding HTML tag’s src attribute with a module-relative URL.

Yes

No

property

Same as the corresponding HTML tag’s name attribute.Specifies the name that will be associated with this control.

Yes

No

src

Same as the corresponding HTML tag’s attribute with the same name.Specifies the source URL for this button’s image.

Yes

No

srcKey

Specifies a key from Struts’ ApplicationResources.properties file whose value will be used to set the corresponding HTML tag’s src attribute.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that this control will be populated with. If not specified, this tag will attempt to use its body content as the value.

Yes

No

Example Usage

As mentioned, there are two ways you can use the image tag. The first way, shown here, uses the page attribute to specify a module-relative URL for the generated HTML tag’s src attribute:

<html:image page="previous.gif"/>

The second way to use the image tag is shown here:

<html:image src="/books/1/248/1/html/2//images/next.gif"/> 

This example uses the src attribute to specify a URL for the generated HTML tag’s src attribute. The image tag will be used in this way for most applications; however, if you are taking advantage of Struts’ module functionality, you will use the page or pageKey attribute.

The img Tag

The img tag is used to generate an HTML <img> tag. The image’s URL is composed by specifying a base URL and optionally specifying query string parameters to add to the URL.

Attributes

Attribute

Description

Accepts Scriptlet

Required

action

Specifies the name of an action, from the Action Mappings Configuration section of the Struts configuration file, that contains the base URL for the image.

Yes

No

align

Same as the corresponding HTML tag’s attribute with the same name.Specifies how the image will be aligned (i.e., left, right, top, bottom, and so on).

Yes

No

alt

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

border

Same as the corresponding HTML tag’s attribute with the same name.Specifies the width of the border surrounding the image.

Yes

No

bundle

Specifies the logical name of a resource bundle that will be used to look up messages for this tag.

Yes

No

height

Same as the corresponding HTML tag’s attribute with the same name.Specifies the height of this image in pixels.

Yes

No

hspace

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of pixels that will be placed between this image and text surrounding it from the top or bottom.

Yes

No

imageName

Same as the corresponding HTML tag’s name attribute.Specifies the scriptable name for the image.

Yes

No

ismap

Same as the corresponding HTML tag’s attribute with the same name.Specifies the name of a server-side image map to use to map different regions of the image to different URLs.

Yes

No

locale

Specifies the key for a java.util.Locale instance stored as a session attribute that will be used when looking up message keys specified by other attributes of this tag (i.e., pageKey and srcKey).

Yes

No

lowsrc

DeprecatedThis attribute has been removed from the HTML spec as of version 4.01 and will no longer be supported in future versions of Struts.

Yes

No

module

Specifies the name of a module that contains the action specified with the action attribute.

Yes

No

name

Specifies the name of the java.util.Map object whose elements are added as query string parameters to the URL for this image. If the property attribute is also specified, one of the fields of the object defined by this attribute will have its getter method called to return the java.util.Map object whose elements are added as query string parameters to the URL for this image.

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

page

Specifies a module-relative URL for this image.

Yes

No

pageKey

Specifies a key from Struts’ ApplicationResources.properties file whose value will be used to set the corresponding HTML tag’s src attribute with a module-relative URL.

Yes

No

paramId

Specifies the name of a single parameter to add to the URL for this image.

Yes

No

paramName

Specifies the name of an object whose value will be used as the value for the parameter specified with the paramId attribute. If the property attribute is also specified, one of the fields of the object defined by this attribute will have its getter method called to return an object whose value will be used as the value for the parameter specified with the paramId attribute.

Yes

No

paramProperty

Specifies the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used as the value for the parameter specified with the paramId attribute.

Yes

No

paramScope

Specifies the scope (application, page, request, or session) to look in for the object specified by the paramName attribute. If not specified, each scope will be searched, in this order: page, request, session, and then application.

Yes

No

property

Specifies the field of the object specified by the name attribute whose getter method will be called to return the java.util.Map object whose elements are added as query string parameters to the URL for this image.

Yes

No

scope

Specifies the scope (application, page, request, or session) to look in for the object specified by the name attribute. If not specified, each scope will be searched, in this order: page, request, session, and then application.

Yes

No

src

Same as the corresponding HTML tag’s attribute with the same name.Specifies the source URL for this image.

Yes

No

srcKey

Specifies a key from Struts’ ApplicationResources.properties file whose value will be used to set the corresponding HTML tag’s src attribute.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

usemap

Same as the corresponding HTML tag’s attribute with the same name.Specifies the name of a client-side image map to use for mapping different regions of the image to different URLs.

Yes

No

vspace

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of pixels that will be placed between this image and text surrounding it from the left or right.

Yes

No

width

Same as the corresponding HTML tag’s attribute with the same name.Specifies the width of this image in pixels.

Yes

No

Example Usage

There are a few different ways to use the img tag. The first way, shown here, uses the src attribute to specify an absolute URL for the image:

<html:img src="/books/1/248/1/html/2/http://www.domain.com/image.gif"/>

The following example adds to the first example by specifying a single query string parameter to add to the base URL specified by the src attribute:

<html:img href=" http://www.domain.com/image.gif"     param   paramName="imageObj"/>

This example takes the base URL specified by the href attribute and appends the query string parameter specified by the paramId and paramName attributes and composes a URL for the image.

The javascript Tag

The javascript tag is used to generate client-side JavaScript validation code for validations defined in the Validator framework’s validation.xml file.

The JavaScript code generated by the javascript tag can be broken down into two pieces: static code and dynamic code. The static piece is composed of all the generic validation routine methods. The dynamic piece is composed of the code that is specific to a particular HTML form and that calls the static validation methods. Because the static piece of code is typically very large and is often repeated across several pages, it is advantageous to break that piece out and store it in its own file. That way it can simply be referenced by each page that makes use of it. The javascript tag allows you to break up the two pieces of code by specifying which code it generates with the dynamicJavascript and staticJavascript attributes.

Attributes

Attribute

Description

Accepts Scriptlet

Required

cdata

Accepts “false” to denote that the generated JavaScript code will not be enclosed in XML CDATA tags (i.e., <![CDATA[ ]]>).Note that CDATA tags are necessary to prevent JavaScript code from being parsed when used in conjunction with XHTML.

Yes

No

dynamicJavascript

Accepts “false” to denote that dynamic JavaScript will not be generated.

No

No

formName

Specifies the logical name of a Form Bean whose validation rules will be used to generate JavaScript validation code.

Yes

No

htmlComment

Accepts “false” to denote that the generated JavaScript code will not be enclosed in HTML comment tags (i.e., <!- - - ->).

Yes

No

method

Specifies an alternate JavaScript method name to be used instead of the default.

Yes

No

page

Specifies the logical name of a page to use to filter which validations for the specified form will be generated. This logical name matches the logical name that can be applied to individual fields in the validation.xml file.

Yes

No

scriptLanguage

Accepts “false” to denote that the language attribute of the <script> tag generated by this tag should be omitted.Note that the generated <script> tag’s language attribute is omitted regardless when the tags in this library are in XHTML mode.

Yes

No

src

Same as the corresponding JavaScript tag’s attribute with the same name.Specifies the URL to a static JavaScript file to be included.

Yes

No

staticJavascript

Accepts “false” to denote that static JavaScript will not be generated.

No

No

Example Usage

The following snippet illustrates the basic usage of the javascript tag:

<html:javascript formName="logonForm"/> 

This example will generate JavaScript code for all the validation rules in the validation.xml file that are tied to the Form Bean specified by the formName attribute.

If you want to separate the dynamic and static pieces of the generated JavaScript code, you can use the javascript tag as shown next:

<html:javascript formName="logonForm"         staticJavascript="false"               src="/books/1/248/1/html/2/staticJavascript.jsp"/>

This usage only generates the dynamic JavaScript for the specified form. The following example generates the generic static JavaScript code:

<html:javascript formName="logonForm" dynamicJavascript="false"/>

This snippet must be placed into a separate file named staticJavascript.jsp to match the file name specified by the src attribute of the previous example.

The link Tag

The link tag is used to generate an HTML hyperlink <a> tag whose URL is composed by specifying a base URL and optionally specifying an anchor and/or query string parameters to add to the URL.

There are four ways to specify the base URL:

  • You can use the action attribute to specify the name of an Action from the Struts configuration file whose URL will be used.

  • You can use the forward attribute to specify the name of a forward from the Struts configuration file whose URL will be used.

  • You can use the href attribute to specify an absolute URL, including protocol (e.g., http://www.yahoo.com/).

  • You can use the page attribute to specify an application-relative URL.

In addition to specifying the base URL, you have two options for specifying query string parameters to add to the base URL:

  • You can use the paramId attribute in conjunction with the paramName attribute, and optionally the paramProperty attribute, to specify a single parameter.

  • You can use the name attribute, either alone or in tandem with the property attribute, to specify a java.util.Map object that will be used to add several parameters.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

action

Specifies the name of an Action, from the Action Mappings section of the Struts configuration file, that contains the URL for this link.

Yes

No

anchor

Specifies the anchor (e.g., “#bottom”) to be added to the URL for this link. This value must be specified without the leading hash (#) character.

Yes

No

forward

Specifies the name of a forward, from the Global Forwards Configuration section of the Struts configuration file, that contains the URL for this link.

Yes

No

href

Specifies the absolute URL, including protocol (e.g., http://www.yahoo.com), for this link.

Yes

No

indexed

Accepts “true” to denote that an indexed parameter, whose name is specified by the indexId attribute, will be added to the URL for this link.This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

indexId

Specifies the name to use for an indexed parameter if the indexed attribute is used.This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

linkName

Same as the corresponding HTML tag’s name attribute.Specifies the name of a page anchor for intra-page hyperlinks.

Yes

No

module

Specifies the name of a module that contains the action specified with the action attribute.

Yes

No

name

Specifies the name of the java.util.Map object whose elements are added as query string parameters to the URL for this link. If the property attribute is also specified, one of the fields of the object defined by this attribute will have its getter method called to return the java.util.Map object whose elements are added as query string parameters to the URL for this link.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

page

Specifies the application-relative URL (starts with a leading slash, /) for this link.

Yes

No

paramId

Specifies the name of a single parameter to add to the URL for this link.

Yes

No

paramName

Specifies the name of an object whose value will be used as the value for the parameter specified with the paramId attribute. If the property attribute is also specified, one of the fields of the object defined by this attribute will have its getter method called to return an object whose value will be used as the value for the parameter specified with the paramId attribute.

Yes

No

paramProperty

Specifies the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used as the value for the parameter specified with the paramId attribute.

Yes

No

paramScope

Specifies the scope (application, page, request, or session) to look in for the object specified by the paramName attribute. If not specified, each scope will be searched, in this order: page, request, session, and then application.

Yes

No

property

Specifies the field of the object specified by the name attribute whose getter method will be called to return the java.util.Map object whose elements are added as query string parameters to the URL for this link.

Yes

No

scope

Specifies the scope (application, page, request, or session) to look in for the object specified by the name attribute. If not specified, each scope will be searched, in this order: page, request, session, and then application.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

transaction

Accepts “true” or “false” to denote whether or not the current transaction token will be included in the URL for this link.

Yes

No

Example Usage

There are a few different ways to use the link tag. The first way, shown here, uses the href attribute to specify an absolute URL for the frame:

<html:link href="http://www.yahoo.com/"/>

The following example adds to the first example by specifying a single query string parameter to add to the base URL specified by the href attribute:

<html:link href="http://www.yahoo.com/"        param     paramName="queryObj"/>

This example takes the base URL specified by the href attribute and appends the query string parameter specified by the paramId and paramName attributes and composes a URL that the tag then redirects to.

Another way to use the link tag is shown here:

<html:link page="/search.jsp" name="params"/>

This example uses the page attribute to specify an application-relative base URL and uses the name attribute to specify a java.util.Map object whose entries are added to the URL as query string parameters.

The messages Tag

The messages tag is used to display a set of messages stored as an org.apache.struts .action.ActionErrors object, an org.apache.struts.action.ActionMessages object, a String, or a String array in request scope. Similar to the errors tag, this tag will take the stored messages and iterate over them; however, instead of actually outputting the messages to the JSP, this tag behaves similar to the Logic Tag Library’s iterate tag. On each iteration, it stores the current message in a page scope JSP variable.

Attributes

Attribute

Description

Accepts Scriptlet

Required

bundle

Specifies the logical name of a resource bundle that will be used when looking up message keys specified by other attributes of this tag (e.g., footer and header).

Yes

No

footer

Specifies a key from Struts’ ApplicationResources.properties file whose value will be printed after the messages have been iterated through.

Yes

No

header

Specifies a key from Struts’ ApplicationResources.properties file whose value will be printed before the messages have been iterated through.

Yes

No

id

Specifies the name for a page scope JSP variable that will hold a reference to the current message on each iteration.

No

Yes

locale

Specifies the key for a java.util.Locale instance stored as a session attribute that will be used when looking up message keys specified by other attributes of this tag (e.g., footer and header).

Yes

No

message

Accepts “true” to denote that the messages to be displayed are stored under the org.apache.struts.Globals.MESSAGE_KEY key instead of the org.apache.struts.Globals.ERROR_KEY key.

Yes

No

name

Specifies the key (in any scope) under which the messages to be displayed are stored. If not specified, the default org.apache.struts.Globals.ERROR_KEY key will be used.

Yes

No

property

Specifies the field for which messages will be displayed. If not specified, all messages will be displayed.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the messages tag:

<html:messages > <li><bean:write name="msg"/></li> </html:messages>

This example will display all the messages currently stored. If you want to limit the messages that are displayed to a specific property, you can specify that property when using the messages tag, as shown here:

<html:messages  property="category"> <li><bean:write name="msg"/></li> </html:messages>

In this case, only the messages associated with the property specified by the property attribute will be displayed.

The multibox Tag

The multibox tag is used to generate an HTML <input type=“checkbox”> tag whose checked status is based on whether or not a specified value matches one of the values in a specified array of values. This tag is useful when your JSP is displaying several check boxes at a time. Instead of using several instances of the checkbox tag, you can use this tag in conjunction with the Logic Tag Library’s iterate tag to reduce the amount of code it takes to deal with several check boxes.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will be used to populate this control with data.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Specifies the value to set the corresponding HTML tag’s name attribute to.Additionally, this attribute is used to specify the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used to populate this control. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

Yes

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that the control will be populated with.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the multibox tag:

<logic:iterate  property="items">   <html:multibox property="selectedItems">    <bean:write name="item"/>    </html:multibox>    <bean:write name="item"/>  </logic:iterate>

In this example, the iterate tag loops through each of the elements in the collection specified by its property attribute. Each iteration of the loop uses the multibox tag to generate an HTML <input type=“checkbox”> tag whose checked status is based on whether or not the loop’s current element is present in the collection specified by the property attribute of the multibox tag.

The option Tag

The option tag is used to generate an HTML <option> tag. Note that this tag must be nested inside of the select tag. If an instance of this tag’s value matches the value of the Form Bean field corresponding to the enclosing select tag, the instance will be marked as selected.

Attributes

Attribute

Description

Accepts Scriptlet

Required

bundle

Specifies the logical name of a resource bundle that will be used to look up the message specified by the key attribute.

Yes

No

disabled

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

key

Specifies a key from Struts’ ApplicationResources.properties file whose value will be used to set the text that will be displayed for this option. If not specified, the text displayed for this option will be taken from this tag’s body content.

Yes

No

locale

Specifies the key for a java.util.Locale instance stored as a session attribute that will be used when looking up the message specified by the key attribute.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that the control will be populated with.

Yes

Yes

Example Usage

The following snippet illustrates the basic usage of the option tag:

<html:select property="gender">   <html:option value="male">Male</html:option>    <html:option value="female">Female</html:option> </html:select>

If the value specified by an option tag’s value attribute matches the value of the Form Bean field specified by the select tag’s property attribute, the HTML <option> tag will be marked as selected when it is generated.

The options Tag

The options tag is used to generate a set of HTML <option> tags for each element in a collection. Note that this tag must be nested inside of the select tag.

There are three ways you can specify which collection to generate options from, as listed here and shown later in the “Example Usage” section:

  • You can use the collection attribute to specify a scriptlet that evaluates to a collection object.

  • You can use the name attribute to specify the name of a collection object that can be in any scope.

  • You can use the name and property attributes in tandem to specify the name of an object and its field whose getter method will be called to return a collection object.

Attributes

Attribute

Description

Accepts Scriptlet

Required

collection

Specifies the name of a collection object (in any scope) whose elements will be used to create a set of options.

Yes

No

filter

Accepts “false” to denote that option labels will not be filtered for sensitive HTML characters (e.g., > and <).

Yes

No

labelName

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will have its getter method called to return a collection object whose elements will be used as labels for the created options.

Yes

No

labelProperty

Specifies the field of the object specified by the name attribute whose getter method will be called to return a collection object whose elements will be used as labels for the created options. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will have its getter method called to return a collection object whose elements will be used to create a set of options.

Yes

No

property

Specifies the field of the object specified by the name attribute whose getter method will be called to return a collection object whose elements will be used to create a set of options. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

No

style

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

Example Usage

As mentioned there are three basic ways you can use the options tag. The first way, shown here, uses the collection attribute to specify the collection from which to create options:

<html:select property="category">   <html:options collection="catOptions"/> </html:select>

This example assumes you have defined a collection named “category” and then uses its elements to generate a set of options.

The second way to use the options tag is shown here:

<html:select property="category">   <html:options name="catOptions"/> </html:select> 

This example is very similar to the first example; however, it differs in that the collection from which to generate options is specified with the name attribute.

The third way to use the options tag is shown here:

<html:select property="category">   <html:options name="cat" property="options"/> </html:select>

In this example, the name and property attributes are used in tandem to specify the name of an object and its field whose getter method will be called to return a collection for which to generate options.

The optionsCollection Tag

The optionsCollection tag is used to generate a set of HTML <option> tags for each element in a collection. This tag is very similar to the options tag, but differs in that it requires the objects in the specified collection to have fields for the generated options’ labels and values. Note that this tag must be nested inside of the select tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

filter

Accepts “false” to denote that option labels will not be filtered for sensitive HTML characters (e.g., > and <).

Yes

No

label

Specifies the field of the object specified with the name and property attributes whose value will be used as the label for the generated options.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will have its getter method called to return a collection object whose elements will be used to create a set of options.

Yes

No

property

Specifies the field of the object specified by the name attribute whose getter method will be called to return a collection object whose elements will be used to create a set of options. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

No

style

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

value

Specifies the field of the object specified with the name and property attributes whose value will be used as the value for the generated options.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the optionsCollection tag:

<html:select property="category">   <html:optionsCollection name="cat" property="options"/> </html:select>

In this example, the name and property attributes are used in tandem to specify the name of an object and its field whose getter method will be called to return a collection for which to generate options.

The password Tag

The password tag is used to generate an HTML <input type=“password”> tag populated with data from a specified object. Note that this tag must be nested inside of the form tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index (e.g., “name[x].property”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

maxlength

Same as the corresponding HTML tag’s attribute with the same name.Specifies the maximum number of characters that this control will accept.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will be used to populate this control with data.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Specifies the value to set the corresponding HTML tag’s name attribute to.Additionally, this attribute is used to specify the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used to populate this control. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

Yes

readonly

Same as the corresponding HTML tag’s attribute with the same name.Accepts “true” to denote that the control’s value will be read-only, preventing it from being changed.

Yes

No

redisplay

Accepts “false” to denote that the value specified with the name and property attributes or specified with the value attribute will not be used to populate this control.

Yes

No

size

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of characters that will be visible in the control.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that the control will be populated with.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the password tag:

<html:form action="/logon"> UserName: <html:text property="username"/><br> Password: <html:password property="password"/><br> <html:submit/> </html:form>

This tag will look up the Form Bean associated with the Action specified by the form tag’s action attribute and then call the getter method for the field specified by this tag’s property attribute. The field’s value will then be used to populate the HTML control with data.

The radio Tag

The radio tag is used to generate an HTML <input type=“radio”> tag populated with data from a specified object. Note that this tag must be nested inside of the form tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

idName

If an iterator is used to generate a series of radio tags, this attribute can be used to specify a name for the object exposed by the iterator. In this case, the value attribute is used as the name of a field on the exposed object whose getter method will be called to return the value that the radio tag for this iteration will be populated with.

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index (e.g., “name[x].property”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will be used to populate this control with data.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Specifies the value to set the corresponding HTML tag’s name attribute to.Additionally, this attribute is used to specify the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used to populate this control. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

Yes

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that the control will be populated with.

Yes

Yes

Example Usage

The following snippet illustrates the basic usage of the radio tag:

<html:form action="/register"/> Male: <html:radio property="gender" value="male"/><br> Female: <html:radio property="gender" value="female"/><br> <html:submit/> </html:form> 

This tag will look up the Form Bean associated with the Action specified by the form tag’s action attribute and then call the getter method for the field specified by this tag’s property attribute. If the field’s value matches the value specified with the value attribute, the radio button will be selected.

The reset Tag

The reset tag is used to generate an HTML <input type=“reset”> tag. Note that this tag must be nested inside of the form tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Same as the corresponding HTML tag’s name attribute.Specifies the name that will be associated with this control.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that this control will be populated with.This value will be used for the button’s label. If not specified, this tag will attempt to use its body content as the value for the button’s label.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the reset tag:

<html:reset value="Reset Form"/>

The value specified with the value attribute will be used for the button’s label. Alternatively, you can specify the button’s label value by nesting a string between opening and closing reset tags, as shown here:

<html:reset>Reset Form</html:reset>

The rewrite Tag

Similar to the link tag, the rewrite tag is used to generate a URL by specifying a base URL and optionally specifying an anchor and/or query string parameters to add to the URL. However, this tag does not create an HTML <a> tag for the generated URL. This tag is useful for creating URLs that are used as string constants in JavaScript code.

There are four ways to specify the base URL:

  • You can use the action attribute to specify the name of an Action from the Struts configuration file whose URL will be used.

  • You can use the forward attribute to specify the name of a forward from the Struts configuration file whose URL will be used.

  • You can use the href attribute to specify an absolute URL, including protocol (e.g., http://www.yahoo.com/).

  • You can use the page attribute to specify an application-relative URL.

In addition to specifying the base URL, you have two options for specifying query string parameters to add to the base URL:

  • You can use the paramId attribute in conjunction with the paramName attribute, and optionally the paramProperty attribute, to specify a single parameter.

  • You can use the name attribute, either alone or in tandem with the property attribute, to specify a java.util.Map object that will be used to add several parameters.

Attributes

Attribute

Description

Accepts Scriptlet

Required

action

Specifies the name of an action, from the Action Mappings Configuration section of the Struts configuration file, that contains the base URL for the generated URL.

Yes

No

anchor

Specifies the anchor (e.g., “#bottom”) to be added to the generated URL. This value must be specified without the leading hash (#) character.

Yes

No

forward

Specifies the name of a forward, from the Global Forwards Configuration section of the Struts configuration file, that contains the base URL for the generated URL.

Yes

No

href

Specifies the absolute base URL, including protocol (e.g., http://www.yahoo.com), for the generated URL.

Yes

No

module

Specifies the name of a module that contains the action specified with the action attribute.

Yes

No

name

Specifies the name of the java.util.Map object whose elements are added as query string parameters to the generated URL. If the property attribute is also specified, one of the fields of the object defined by this attribute will have its getter method called to return the java.util.Map object whose elements are added as query string parameters to the generated URL.

Yes

No

page

Specifies the application-relative base URL (starts with a leading slash, /) for the generated URL.

Yes

No

paramId

Specifies the name of a single parameter to add to the generated URL.

Yes

No

paramName

Specifies the name of an object whose value will be used as the value for the parameter specified with the paramId attribute. If the property attribute is also specified, one of the fields of the object defined by this attribute will have its getter method called to return an object whose value will be used as the value for the parameter specified with the paramId attribute.

Yes

No

paramProperty

Specifies the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used as the value for the parameter specified with the paramId attribute.

Yes

No

paramScope

Specifies the scope (application, page, request, or session) to look in for the object specified by the paramName attribute. If not specified, each scope will be searched, in this order: page, request, session, and then application.

Yes

No

property

Specifies the field of the object specified by the name attribute whose getter method will be called to return the java.util.Map object whose elements are added as query string parameters to the generated URL.

Yes

No

scope

Specifies the scope (application, page, request, or session) to look in for the object specified by the name attribute. If not specified, each scope will be searched, in this order: page, request, session, and then application.

Yes

No

transaction

Accepts “true” or “false” to denote whether or not the current transaction token will be included in the generated URL.

Yes

No

Example Usage

There are a few different ways to use the rewrite tag. The first way, shown here, uses the href attribute to specify an absolute URL for the frame:

<html:rewrite href="http://www.yahoo.com/"/>

The following example adds to the first example by specifying a single query string parameter to add to the base URL specified by the href attribute:

<html:rewrite href="http://www.yahoo.com/"         param     paramName="queryObj"/>

This example takes the base URL specified by the href attribute and appends the query string parameter specified by the paramId and paramName attributes and composes a URL that the tag then redirects to.

Another way to use the rewrite tag is shown here:

<html:rewrite page="/search.jsp" name="params"/> 

This example uses the page attribute to specify an application-relative base URL and uses the name attribute to specify a java.util.Map object whose entries are added to the URL as query string parameters.

The select Tag

The select tag is used to generate an HTML <select> tag. Note that this tag must be nested inside of the form tag.

There are two ways you can use the select tag, as listed here and shown later in the “Example Usage” section:

  • You can omit the multiple attribute so that only one selection can be made. If you take this route, the property attribute must evaluate to a scalar value for the nested option that is selected.

  • You can assign an arbitrary value to the multiple attribute so that multiple selections can be made. If you take this route, the property attribute must evaluate to an array of scalar values for each nested option that is selected.

Attributes

Attribute

Description

Accepts Scriptlet

Required

alt

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index (e.g., “name[x].property”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

multiple

Same as the corresponding HTML tag’s attribute with the same name.Accepts an arbitrary value to denote that multiple selections can be made on the control.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will be used to determine which nested option tag will be set as selected.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Specifies the value to set the corresponding HTML tag’s name attribute to.Additionally, this attribute is used to specify the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used to determine which nested option tag will be set as selected. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

Yes

size

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of options that will be visible at a time.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies the value to use when determining which nested option tag will be set as selected.

Yes

No

Example Usage

As mentioned, there are two ways you can use the select tag. The first way, shown here, omits the multiple attribute so that only one nested option will be selected:

<html:select property="gender">   <html:option value="male">Male</html:option>    <html:option value="female">Female</html:option> </html:select> 

The second way to use the select tag is shown here:

<html:select property="color" multiple="true" size="3">   <html:option value="red">Red</html:option>    <html:option value="green">Green</html:option>   <html:option value="blue">Blue</html:option>   <html:option value="black">Black</html:option>   <html:option value="white">White</html:option> </html:select>

This example uses the multiple attribute to denote that the object specified with the property attribute will be an array of values for each nested option that will be selected.

The submit Tag

The submit tag is used to generate an HTML <input type=“submit”> tag. Note that this tag must be nested inside of the form tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index (e.g., “property[x]”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Same as the corresponding HTML tag’s name attribute.Specifies the name that will be associated with this control.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that this control will be populated with.This value will be used as the button’s label.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the submit tag:

<html:submit value="Add Record"/>

The value specified with the value attribute will be used for the button’s label. Alternatively, you can specify the button’s label value by nesting a string between opening and closing submit tags, as shown here:

<html:submit>Next Page</html:submit>

The text Tag

The text tag is used to generate an HTML <input type=“text”> tag populated with data from a specified object. Note that this tag must be nested inside of the form tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute must have an index (e.g., “name[x].property”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

maxlength

Same as the corresponding HTML tag’s attribute with the same name.Specifies the maximum number of characters that this control will accept.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will be used to populate this control with data.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Specifies the value to set the corresponding HTML tag’s name attribute to.Additionally, this attribute is used to specify the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used to populate this control. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

Yes

readonly

Same as the corresponding HTML tag’s attribute with the same name.Accepts “true” to denote that the control’s value will be read-only, preventing it from being changed.

Yes

No

size

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of characters that will be visible in the control.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that the control will be populated with.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the text tag:

<html:form action="/search"> Search Query: <html:text property="query"/><br> <html:submit/> </html:form>

This tag will look up the Form Bean associated with the Action specified by the form tag’s action attribute and then call the getter method for the field specified by this tag’s property attribute. The field’s value will then be used to populate the HTML control with data.

The textarea Tag

The textarea tag is used to generate an HTML <textarea> tag populated with data from a specified object. Note that this tag must be nested inside of the form tag.

Attributes

Attribute

Description

Accepts Scriptlet

Required

accesskey

See the “Common Tag Attributes” section at the end of this chapter.

Yes

No

alt

See “Common Tag Attributes.”

Yes

No

altKey

See “Common Tag Attributes.”

Yes

No

cols

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of columns to display.

Yes

No

disabled

See “Common Tag Attributes.”

Yes

No

indexed

Accepts “true” to denote that the value assigned to the corresponding HTML tag’s name attribute will have an index (e.g., “name[x].property”).This attribute is applicable only when this tag is nested inside the Logic Tag Library’s iterate tag.

Yes

No

name

Specifies the name of an object (in any scope) whose field, specified by the property attribute, will be used to populate this control with data.

Yes

No

onblur

See “Common Tag Attributes.”

Yes

No

onchange

See “Common Tag Attributes.”

Yes

No

onclick

See “Common Tag Attributes.”

Yes

No

ondblclick

See “Common Tag Attributes.”

Yes

No

onfocus

See “Common Tag Attributes.”

Yes

No

onkeydown

See “Common Tag Attributes.”

Yes

No

onkeypress

See “Common Tag Attributes.”

Yes

No

onkeyup

See “Common Tag Attributes.”

Yes

No

onmousedown

See “Common Tag Attributes.”

Yes

No

onmousemove

See “Common Tag Attributes.”

Yes

No

onmouseout

See “Common Tag Attributes.”

Yes

No

onmouseover

See “Common Tag Attributes.”

Yes

No

onmouseup

See “Common Tag Attributes.”

Yes

No

property

Specifies the value to set the corresponding HTML tag’s name attribute to.Additionally, this attribute is used to specify the field of the object specified by the name attribute whose getter method will be called to return an object whose value will be used to populate this control. If no object is specified with the name attribute, the Form Bean object associated with the enclosing form tag will be used to retrieve the property specified by this attribute.

Yes

Yes

readonly

Same as the corresponding HTML tag’s attribute with the same name.Accepts “true” to denote that the control’s value will be read-only, preventing it from being changed.

Yes

No

rows

Same as the corresponding HTML tag’s attribute with the same name.Specifies the number of rows to display.

Yes

No

style

See “Common Tag Attributes.”

Yes

No

styleClass

See “Common Tag Attributes.”

Yes

No

styleId

See “Common Tag Attributes.”

Yes

No

tabindex

See “Common Tag Attributes.”

Yes

No

title

See “Common Tag Attributes.”

Yes

No

titleKey

See “Common Tag Attributes.”

Yes

No

value

Specifies a constant value that the control will be populated with.

Yes

No

Example Usage

The following snippet illustrates the basic usage of the textarea tag:

<html:form action="/feedback"> Comments: <html:textarea property="comments"/><br> <html:submit/> </html:form>

This tag will look up the Form Bean associated with the Action specified by the form tag’s action attribute and then call the getter method for the field specified by this tag’s property attribute. The field’s value will then be used to populate the HTML control with data.

The xhtml Tag

The xhtml tag causes the rest of the tags in the HTML Tag Library to generate their output as XHTML instead of HTML. For more information on XHTML, see http://www.w3.org/TR/xhtml1/.

Using this tag is equivalent to using this library’s html tag with the xhtml attribute set to “true”, as shown here:

<html:html xhtml="true"/>

Attributes

This tag does not have any attributes.

Example Usage

Using the xhtml tag is very simple because it has no attributes that can or need to be set. You simply just use the tag as shown here:

<html:xhtml/>

You must place this tag before using any other tags from this library; otherwise, they will not know to generate XHTML. Note that using this tag will not guarantee that your JSP is 100 percent XHTML compliant; you must ensure that any direct usages of HTML tags also conform.



 < Day Day Up > 



Struts. The Complete Reference
Struts: The Complete Reference, 2nd Edition
ISBN: 0072263865
EAN: 2147483647
Year: 2003
Pages: 134
Authors: James Holmes

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net