OpMath

com.opmath.util.html
Class Select

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--com.opmath.util.datastruct.OrderedHashtable
                    |
                    +--com.opmath.util.datastruct.UCHashtable
                          |
                          +--com.opmath.util.datastruct.ComparableTable
                                |
                                +--com.opmath.util.html.Select
All Implemented Interfaces:
Cloneable, Map, Serializable

public class Select
extends ComparableTable

A representation of an HTML <SELECT > structure, compatible with com.opmath.util.datastruct.ComparableTable.

The Select class addresses the problem of regenerating a <SELECT ...> structure - with the SELECTED tag parameter set on the correct <OPTION...> tags. The Select structure carries three com.opmath.util.datastruct.ComparableLists, one for each of the three 'dimensions' of the <OPTION...> tags in the <SELECT ...> structure: NAME, VALUE and optional SELECTED.

To use Select, first create an instance; the minimum specification for this is a String[] of names:

String[] myNames = { "Natasha", "Bruno", "Mathew" };
Select mySelection = new Select("people", myNames);

To set one of these as SELECTED, do:

mySelection.setSelectedName("Bruno");

To add the result to the document's model, do:

model.register(mySelection);

This last line assumes that the model contains the substitution sources 'peopleNames', 'peopleValues' and 'peopleSelect'. In other words, the HTML template contains something like:

<!-- SUB peopleNames SUB_PEOPLE_NAMES -->
<!-- SUB peopleValues SUB_PEOPLE_VALUES -->
<!-- SUB peopleSelect SUB_PEOPLE_SELECT -->
...
<SELECT NAME="people">
<!-- LOOP -->
<OPTION VALUE="SUB_PEOPLE_VALUES" SUB_PEOPLE_SELECT>SUB_PEOPLE_NAMES</OPTION>
<!-- ENDLOOP -->
</SELECT>

NOTE: The design of the Select class assumes that the names for the SELECT structure must be unqiue. In contrast, the values for the SELECT structure normally will be unique, but are not required to be.

Copyright: (c) 2002 The Open Math Company Limited

The Terms of Distribution of this software are stipulated in the javadoc Overview for this project.

Since:
J2SE 1.3
Version:
utilities-v011
Author:
Bruno Beloff bruno.beloff@opmath.com
See Also:
Serialized Form

Constructor Summary
Select(String id, String[] names)
          Constructs a new Select instance with each OPTION NAME and OPTION VALUE sourced from the parameter names.
Select(String id, String[] names, Comparable[] values)
          Constructs a new Select instance with each OPTION NAME sourced from the parameter names and each OPTION VALUE sourced from the parameter values.
Select(String id, String[] names, Comparable[] values, String[] select)
          Constructs a new Select instance with each OPTION NAME sourced from the parameter names, each OPTION VALUE sourced from the parameter values, and each OPTION SELECTED sourced from the parameter select.
 
Method Summary
 void clear()
          Sets all the OPTION elements to "" (not selected).
 void clearSelectedName(Comparable name)
          Sets the OPTION element whose NAME is equal to name to "" (not selected).
 void clearSelectedValue(Comparable value)
          Sets the OPTION element whose VALUE is equal to value to "" (not selected).
 void setSelectedName(Comparable name)
          Sets the OPTION element whose NAMES is equal to name to "SELECTED".
 void setSelectedValue(Comparable value)
          Sets the OPTION element whose VALUE is equal to value to "SELECTED".
 
Methods inherited from class com.opmath.util.datastruct.ComparableTable
addColumn, addColumn, appendObject, appendTo, columnSize, getAt, getColumn, getColumns, getRows, maxColumnSize, register, register, register, registerColumn, sort, sort, toString, updateAt, updateColumn
 
Methods inherited from class com.opmath.util.datastruct.UCHashtable
normalized
 
Methods inherited from class com.opmath.util.datastruct.OrderedHashtable
containsKey, elements, get, keys, put, putAll, remove
 
Methods inherited from class java.util.Hashtable
clone, contains, containsValue, entrySet, equals, hashCode, isEmpty, keySet, rehash, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Select

public Select(String id,
              String[] names)
       throws ComparableTableException
Constructs a new Select instance with each OPTION NAME and OPTION VALUE sourced from the parameter names. The SELECT structure is named id.

The SELECT structure will contain as many OPTION elements as there are elements in names. Each OPTION element has NAME names[i] and VALUE names[i].

Parameters:
id - the String for the id.
names - the String[] for the OPTION elements.
Throws:
com.opmath.util.datastructure.ComparableTableException - An exception thrown if the names is null or if names contains non-unique Strings.
ComparableTableException
Since:
J2SE 1.3

Select

public Select(String id,
              String[] names,
              Comparable[] values)
       throws ComparableTableException
Constructs a new Select instance with each OPTION NAME sourced from the parameter names and each OPTION VALUE sourced from the parameter values. The SELECT structure is named id.

The length of names must equal the length of values. Each OPTION element has NAME names[i] and VALUE values[i]. Initially, none of the the OPTION elements are set to SELECTED.

Parameters:
id - the String for the id.
names - the String[] for the OPTION element NAMEs.
values - the String[] for the OPTION element VALUEs.
Throws:
com.opmath.util.datastructure.ComparableTableException - An exception thrown if names or values is null, if names contains non-unique Strings, or there is a length mismatch of names / values.
ComparableTableException
Since:
J2SE 1.3

Select

public Select(String id,
              String[] names,
              Comparable[] values,
              String[] select)
       throws ComparableTableException
Constructs a new Select instance with each OPTION NAME sourced from the parameter names, each OPTION VALUE sourced from the parameter values, and each OPTION SELECTED sourced from the parameter select. The SELECT structure is named id.

The length of names must equal the length of values and the length of select. Each OPTION element has NAME names[i], VALUE values[i], and SELECTED select[i]. Each element of select must be set to "" or "SELECTED".

Parameters:
id - the String for the id.
names - the String[] for the OPTION element NAMEs.
values - the String[] for the OPTION element VALUES.
select - the String[] for the OPTION element SELECTED.
Throws:
com.opmath.util.datastructure.ComparableTableException - An exception thrown if names, values or selected is null, if names contains non-unique Strings, or there is a length mismatch of names / values / selected.
ComparableTableException
Since:
J2SE 1.3
Method Detail

setSelectedValue

public void setSelectedValue(Comparable value)
                      throws ComparableTableException
Sets the OPTION element whose VALUE is equal to value to "SELECTED".

All the OPTION element VALUES in a Select should normally be unique. However, if value identifies a non-unique element, then only the first matching element is updated.

Parameters:
value - the Comparable identifying the OPTION element.
Throws:
com.opmath.util.datastructure.ComparableTableException - An exception thrown if value is null, or value is not in this Select instance.
ComparableTableException
Since:
J2SE 1.3

clearSelectedValue

public void clearSelectedValue(Comparable value)
                        throws ComparableTableException
Sets the OPTION element whose VALUE is equal to value to "" (not selected).

All the OPTION element VALUES in a Select should normally be unique. However, if value identifies a non-unique element, then only the first matching element is updated.

Parameters:
value - the Comparable identifying the OPTION element.
Throws:
com.opmath.util.datastructure.ComparableTableException - An exception thrown if value is null, or value is not in this Select instance.
ComparableTableException
Since:
J2SE 1.3

setSelectedName

public void setSelectedName(Comparable name)
                     throws ComparableTableException
Sets the OPTION element whose NAMES is equal to name to "SELECTED".

Throws:
com.opmath.util.datastructure.ComparableTableException - An exception thrown if name is null, or name is not in this Select instance.
ComparableTableException
Since:
J2SE 1.3

clearSelectedName

public void clearSelectedName(Comparable name)
                       throws ComparableTableException
Sets the OPTION element whose NAME is equal to name to "" (not selected).

Throws:
com.opmath.util.datastructure.ComparableTableException - An exception thrown if name is null, or name is not in this Select instance.
ComparableTableException
Since:
J2SE 1.3

clear

public void clear()
Sets all the OPTION elements to "" (not selected).

Specified by:
clear in interface Map
Overrides:
clear in class ComparableTable
Since:
J2SE 1.3

OpMath

Submit a bug or feature to Open Math
Copyright © 2002 Open Math Company Limited, Brighton, UK