Common Tag Attributes


The HTML Tag Library Tags (Continued)

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

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 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 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, which 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 specify whether the current transaction token will be included in the generated URL.

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 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 section "Example Usage":

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

Required

alt

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

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

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

indexed

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

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

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

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

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

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 thsat 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.



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