Home

This Chapter
-Chapter 3: The HTML Tag Library
-The html Tag
-The base Tag
-The form Tag
-The text, password, hidden, textarea Tags
-The submit and cancel Tags
-The reset Tag
-The button Tag
-The checkbox Tag
-The multibox Tag
-The radio Tag
-The select Tag
-The option Tag
-The options Tag
-The optionsCollection Tag
-The link Tag
-The img Tag
-The rewrite Tag
-The frame Tag
-The image Tag
-The xhtml Tag
-Summary

Table of Contents
-Introduction
-Chapter 1: Model 2 and Struts
-Chapter 2: Input Validation with Action Forms
-Chapter 3: The HTML Tag Library
-Chapter 4: Input Validation and Data Conversion
-Chapter 5: The Validator Plugin
-Chapter 6: The Expression Language
-Chapter 7: JSTL
-Chapter 8: The Bean Tag Library
-Chapter 9: The Logic Tag Library
-Chapter 10: Struts-EL, Nested, selectLabel
-Chapter 11: Message Handling and Internationalization
-Chapter 12: The Tiles Framework
-Chapter 13: Securing Struts Applications
-Chapter 14: The Config Object
-Chapter 15: The Persistence Layer
-Chapter 16: Object Caching
-Chapter 17: File Upload and File Download
-Chapter 18: Paging and Sorting
-Chapter 19: Preventing Double Submits
-Chapter 20: Early HttpSession Invalidation
-Chapter 21: Decorating Request Objects
-Chapter 22: How Struts Works

Previous
Next

 

Chapter 3

The HTML Tag Library

Chapter 2 discussed the use of action forms for validating user input. And, you can reap more benefits of Struts if you use action forms in conjunction with the tags in the HTML Tag Library. The following are what you can get from the library.

Note

The HTML Tag Library is one of the three core tag libraries in Struts. The other two are the Bean Tag Library and the Logic Tag Library (discussed in Chapters 8 and 9, respectively).

This chapter deals with each of the HTML Tag Library’s tags. Mostly for your smoother learning experience, the tags are not presented in alphabetical order, but easier tags are given first. Also, some tags are similar and teaching them together saves your time. As such, similar tags are discussed in the same section. Additionally, the ease of mastering a tag sometimes depends on familiarity with another tag. In this case, the tag that should be taught first will appear before the other tag, regardless the names of the tags. Needless to say, this chapter is best read from the first paragraph to the last.

The HTML Tag Library tags are listed in Table 3.1.

Tag Description
base Renders an HTML base element.
button Represents an HTML button.
cancel Represents a submit button for canceling a Struts action.
checkbox Represents a check box.
errors Displays input validation error messages.
file Displays an HTML file element for selecting a file to upload.
form Represents an HTML form.
frame Represents a frame.
hidden Represents a hidden element.
html Renders an html element.
image Represents an image that acts similarly to a submit button.
img Represents a clickable image.
javascript Renders JavaScript functions that support client-side validation in the Validator plugin.
link Represents a hyperlink.
messages Displays messages prepared from inside an action class.
multibox Represents a set of check boxes from which multiple options can be selected.
option Represents an option in a select box
options Represents multiple options in a select box
optionsCollection Represents multiple options in a select box.
password Represents a password element.
radio Represents a radio box.
reset Represents a reset button.
rewrite Renders a URI without creating a hyperlink.
select Represents a select box.
submit Represents a submit button.
text Represents a text field.
textarea Represents a text area.
xhtml Indicates that the HTML tags in the same page must be rendered as XHTML elements, rather than HTML elements.

Table 3.1: The tags in the HTML library

Note

The javascript tag is discussed in Chapter 5, messages in Chapter 11, and file in Chapter 17.

Note

To use the HTML Tag Library and reference its tags indirectly from JSPs, you must add this taglib tag to your web.xml file:

   <taglib>
     <taglib-uri>/tags/struts-html</taglib-uri>
     <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
   </taglib>

On top of that, you must copy the struts-html.tld file (in the lib directory of Struts’ deployment directory) to your WEB-INF directory.

Note

A list of attributes are given for each tag. All attributes are optional except those indicated by an asterisk (*). Default values are underlined.

Attributes of a typical tag falls into two classes: Struts related attributes and HTML attributes. The latter specify JavaScript event handlers and are simply passed to the rendered code by the tag handler. For example, the form tag has the action attribute, which has a special purpose in Struts and will be processed by the tag handler. The form tag also has the onsubmit attribute, which is not processed and will simply be rendered as the onsubmit attribute of the resulting HTML form element. The onsubmit attribute, and many other attributes that do not get processed by Struts, will not be included in the tables of attributes. The purpose of doing so is twofold. First, we save space. Second, you can focus more on the fewer attributes that are Struts-related.

Previous
Next