OpMath

com.opmath.util.html
Class Radio

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.Radio
All Implemented Interfaces:
Cloneable, Map, Serializable

public class Radio
extends ComparableTable

A representation of an HTML <INPUT TYPE="radio" ...> structure, compatible with com.opmath.util.datastruct.ComparableTable.

The Radio class addresses the problem of regenerating a <INPUT TYPE="radio" ...> structure - with the CHECKED tag parameter set on the correct tag. The Radio structure carries four com.opmath.util.datastruct.ComparableLists, one for each of the three 'dimensions' of the <INPUT TYPE="radio"...> tags: NAME, VALUE, descriptive text and optional CHECKED.

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

String[] myNames = { "Natasha", "Bruno", "Mathew" };
String[] myTexts = { "Natasha is the best programmer.", "Bruno is the best programmer.", "Mathew is the best programmer." };
Select myRadioGroup = new Radio("peopleRadio", myNames, myTexts);

To set one of these as SELECTED, do:

myRadioGroup.check("Bruno");

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

model.register(myRadioGroup);

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 peopleRadioNames SUB_PEOPLERADIO_NAMES -->
<!-- SUB peopleRadioValues SUB_PEOPLERADIO_VALUES -->
<!-- SUB peopleRadioText SUB_PEOPLERADIO_TEXT -->
<!-- SUB peopleRadioChecked SUB_PEOPLERADIO_CHECKED -->
...
<!-- LOOP -->
<TD>
<INPUT TYPE="radio" NAME="SUB_PEOPLERADIO_NAMES" VALUE="SUB_PEOPLERADIO_VALUES" SUB_PEOPLERADIO_CHECKED>SUB_PEOPLERADIO_TEXT </TD>

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:
HTTP v2.0
Author:
Bruno Beloff bruno.beloff@opmath.com
See Also:
Serialized Form

Inner classes inherited from class java.util.Map
Map.Entry
 
Constructor Summary
Radio(String id, String[] texts, String[] values)
          Constructs a new Radio instance with each VALUE sourced from the parameter values.
Radio(String id, String[] texts, String[] values, int checkedIndex)
          Constructs a new Radio instance with each VALUE sourced from the parameter values, and each text sourced from the parameter texts[i].
 
Method Summary
 void checkValue(Comparable value)
          Sets the element whose VALUE is equal to value to "CHECKED".
 void clear()
          Sets all the elements' status to "" (not "CHECKED").
 
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

Radio

public Radio(String id,
             String[] texts,
             String[] values)
      throws ComparableTableException
Constructs a new Radio instance with each VALUE sourced from the parameter values. The RADIO structure is named id.

The RADIO structure will contain as many elements as there are elements in values. Each element has VALUE values[i] and text texts[i]. All the elements in values must be unique. Initially, none of the the OPTION elements are set to CHECKED.

Parameters:
id - the String for the id.
texts - the String[] for the elements' texts.
values - the String[] for the elements' values.
Throws:
com.opmath.util.http.ComparableTableException - An exception thrown if the names is null or names and texts are of different lengths, or there are non-unique elements in values.
Since:
J2SE 1.3

Radio

public Radio(String id,
             String[] texts,
             String[] values,
             int checkedIndex)
      throws ComparableTableException
Constructs a new Radio instance with each VALUE sourced from the parameter values, and each text sourced from the parameter texts[i]. The structure is named id.

The int parameter checked specifies which element is initially set to "CHECKED". The value of checked must be greater or equal to 0 and less than the length of each array parameter.

All the elements in values must be unique.

Parameters:
id - the String for the id.
texts - the String[] for the elements' texts.
values - the String[] for the elements' values.
checked - the int specifying the element to be CHECKED.
Throws:
com.opmath.util.http.ComparableTableException - An exception thrown if names, values or selected is null, if or there is a length mismatch of values / texts, or there are non-unique elements in values.
Since:
J2SE 1.3
Method Detail

checkValue

public void checkValue(Comparable value)
                throws ComparableTableException
Sets the element whose VALUE is equal to value to "CHECKED". Any previously checked element is cleared.

All the OPTION element VALUEs in a Select should 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.http.ComparableTableException - An exception thrown if value is null, or value is not in this Radio instance.
Since:
J2SE 1.3

clear

public void clear()
Sets all the elements' status to "" (not "CHECKED").

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