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

 

The select Tag

The select tag is used to generate a select element. A select element can contain zero or many options and can be configured to allow the user to select one or multiple options. Here is the HTML representation of a select element with options.

<select name="fieldname">
  <option value="value_1">label_1</option>
  <option value="value_2">label_2</option>
  ...
  <option value="value_n">label_n</option>
</select>

An option can have a value attribute. When an option is selected, the value of the value attribute of that option is sent to the server. In the absence of a value attribute, the option’s label, which is the text that the user sees for an option, is sent to the server..

Table 3.11 presents the list of attributes of the select tag.

Attribute Description Possible Value(s)
indexed Indicates whether the value assigned to the name attribute is indexed. true or false
multiple The presence of this attribute, with or without a value and regardless what the value is, indicates that multiple options can be selected from the resulting select element.
name The scoped variable containing the property specified by the property attribute. If the name attribute is not present, the value of the enclosing form tag’s name attribute will be used. string
property* The property of the action form mapped to the enclosing form tag that will be associated with the rendered HTML select element. string
size The number of options visible at a time. integer
value Specifies the value of the option that will be set as selected. string

Table 3.11: The select tag’s attributes

For example, here is an example of the select tag. The multiple attribute does not take any value and, when present, allows multiple options to be selected.

<html:select property="propertyName" multiple>
...
</html:select>

To generate a select tag’s options, use one of the following tags: option, options, or optionsCollection or a combination of them. These three tags are given in the sections, “The option Tag”, “The options Tag”, and “The optionsCollection Tag”.

Previous
Next