The HTML Tag Library Tags (Continued)


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 JSP Expression

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 section "Common Tag Attributes" 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

See "Common Tag Attributes."

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

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 the application resource bundle 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 the application resource bundle 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

useLocalEnding

Accepts true or false to specify whether the character encoding of the URL parameters should be performed using the encoding type of the HTTP response object. If this attribute is set to false, the encoding type defaults to UTF-8.

Defaults to false.

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/249/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 JSP Expression

Required

bundle

Specifies the logical name of a resource bundle that will be used when looking up message keys. The referenced resource bundle must be defined in the application's Struts configuration file.

Yes

No

cdata

Accepts true or false to specify whether 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.

Defaults to true.

Yes

No

dynamicJavascript

Accepts true or false to specify whether dynamic JavaScript will be generated.

Defaults to true.

Yes

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 true or false to specify whether the generated JavaScript code will not be enclosed in HTML comment tags (i.e., <!- - - ->).

Defaults to true.

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 Validator configuration file (e.g., validation.xml).

Yes

No

scriptLanguage

Accepts true or false to specify whether 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.

Defaults to true.

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 true or false to specify whether static JavaScript will be generated.

Defaults to true.

Yes

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/249/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 JSP Expression

Required

accesskey

See the section "Common Tag Attributes" 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

bundle

See "Common Tag Attributes."

Yes

No

forward

Specifies the name of a forward, from the Global Forwards section of the Struts configuration file, which 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

See "Common Tag Attributes."

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

target

Same as the corresponding HTML tag's attribute with the same name.

Specifies the frame or window target in which this link will be displayed.

Yes

No

title

See "Common Tag Attributes."

Yes

No

titleKey

See "Common Tag Attributes."

Yes

No

transaction

Accepts true or false to specify whether the current transaction token will be included in the URL for this link.

Defaults to false.

Yes

No

useLocalEnding

Accepts true or false to specify whether the character encoding of the URL parameters should be performed using the encoding type of the HTTP response object. If this attribute is set to false, the encoding type defaults to UTF-8.

Defaults to false.

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 any 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 JSP Expression

Required

bundle

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

Yes

No

footer

Specifies a key from the application resource bundle whose value will be printed after the messages have been iterated through.

Yes

No

header

Specifies a key from the application resource bundle 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 or false to specify whether the messages to be displayed are stored under the org.apache.struts.Globals.MESSAGE_KEY key instead of the org.apa284che.struts.Globals. ERROR_KEY key.

Defaults to false.

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 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 JSP Expression

Required

accesskey

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

Yes

No

alt

See "Common Tag Attributes."

Yes

No

altKey

See "Common Tag Attributes."

Yes

No

bundle

See "Common Tag Attributes."

Yes

No

disabled

See "Common Tag Attributes."

Yes

No

errorKey

Specifies the name of the org.apache.struts. util.MessageResources object that contains the messages to be rendered. Defaults to the value stored in the org.apache.struts. Globals.ERROR_KEY constant.

Yes

No

errorStyle

Specifies the CSS style to apply to this control if an error exists for it.

Yes

No

errorStyleClass

Specifies the CSS class to apply to this control if an error exists for it.

Yes

No

errorStyleId

Specifies the CSS ID to apply to this control if an error exists for it.

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 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 JSP Expression

Required

bundle

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

Yes

No

disabled

See "Common Tag Attributes."

Yes

No

key

Specifies a key from the application resource bundle 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 section "Example Usage":

  • You can use the collection attribute to specify an expression 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 JSP Expression

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 true or false to specify whether option labels will not be filtered for sensitive HTML characters (e.g., > and <).

Defaults to true.

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 section "Common Tag Attributes" 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 it 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 JSP Expression

Required

filter

Accepts true or false to specify whether option labels will not be filtered for sensitive HTML characters (e.g., > and <).

Defaults to true.

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 section "Common Tag Attributes" 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 JSP Expression

Required

accesskey

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

Yes

No

alt

See "Common Tag Attributes."

Yes

No

altKey

See "Common Tag Attributes."

Yes

No

bundle

See "Common Tag Attributes."

Yes

No

disabled

See "Common Tag Attributes."

Yes

No

errorKey

Specifies the name of the org.apache.struts. util.MessageResources object that contains the messages to be rendered. Defaults to the value stored in the org.apache.struts. Globals.ERROR_KEY constant.

Yes

No

errorStyle

Specifies the CSS style to apply to this control if an error exists for it.

Yes

No

errorStyleClass

Specifies the CSS class to apply to this control if an error exists for it.

Yes

No

errorStyleId

Specifies the CSS ID to apply to this control if an error exists for it.

Yes

No

indexed

See "Common Tag Attributes."

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 or false to specify whether the control's value will be read-only, preventing it from being changed.

Defaults to false.

Yes

No

redisplay

Accepts true or false to specify whether the value specified with the name and property attributes or specified with the value attribute will not be used to populate this control.

Defaults to true.

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 JSP Expression

Required

accesskey

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

Yes

No

alt

See "Common Tag Attributes."

Yes

No

altKey

See "Common Tag Attributes."

Yes

No

bundle

See "Common Tag Attributes."

Yes

No

disabled

See "Common Tag Attributes."

Yes

No

errorKey

Specifies the name of the org.apache.struts. util.MessageResources object that contains the messages to be rendered. Defaults to the value stored in the org.apache.struts. Globals.ERROR_KEY constant.

Yes

No

errorStyle

Specifies the CSS style to apply to this control if an error exists for it.

Yes

No

errorStyleClass

Specifies the CSS class to apply to this control if an error exists for it.

Yes

No

errorStyleId

Specifies the CSS ID to apply to this control if an error exists for it.

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

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

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.



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

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