downey
Class PresetCheckedAndSelected

java.lang.Object
  extended bydowney.PresetCheckedAndSelected
All Implemented Interfaces:
java.io.Serializable

public class PresetCheckedAndSelected
extends java.lang.Object
implements java.io.Serializable

A class to simplify the presetting of radio groups, checkbox groups and selection lists

See Also:
Serialized Form

Field Summary
protected  java.util.HashMap mapSelected
          The implementation of the map
 
Constructor Summary
PresetCheckedAndSelected()
          Creates a new instance of PresetCheckedAndSelected
 
Method Summary
 java.lang.String getChecked(java.lang.String key)
          Retrieve a choice from the map: should be either a radio or checkbox element.
 java.lang.String getChoice(java.lang.String key)
          Retrieve a choice from the map.
 java.lang.String getSelected(java.lang.String key)
          Retrieve a choice from the map: should be used in an option for a selection list element.
 void initChoice()
          Reinitializes the map to empty.
 void setChecked(java.lang.String key)
          Set a type of "checked" for this entry in the map.
 void setChecked(java.lang.String[] keys)
          Set a type of "checked" for an array of String keys.
 void setChoice(java.lang.String[] keys, java.lang.String value)
          Set a choice in the map: the type is either "checked" or "selected".
 void setChoice(java.lang.String key, java.lang.String value)
          Set a choice in the map: the type is either "checked" or "selected".
 void setSelected(java.lang.String key)
          Set a type of "selected" for this entry in the map.
 void setSelected(java.lang.String[] keys)
          Set a type of "selected" for an array of String keys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapSelected

protected java.util.HashMap mapSelected
The implementation of the map

Constructor Detail

PresetCheckedAndSelected

public PresetCheckedAndSelected()
Creates a new instance of PresetCheckedAndSelected

Method Detail

initChoice

public void initChoice()
Reinitializes the map to empty. This method will not be used very often. If you need to clear all the old entries, then use this.


getChoice

public java.lang.String getChoice(java.lang.String key)
Retrieve a choice from the map.

Access this from the HTML for the input element
Assume that rec is a record object whose class extends this class, and that team is a checkbox group.

 <input type="checkbox" name="team" value="heat" rec.getChoice("heat")>
 

Parameters:
key - The value from the input element in the form
Returns:
The String value for the given key

getChecked

public java.lang.String getChecked(java.lang.String key)
Retrieve a choice from the map: should be either a radio or checkbox element.

Access this from the HTML for the input element
Assume that rec is a record object whose class extends this class, and that team is a checkbox group.

 <input type="checkbox" name="team" value="heat" rec.getChecked("heat")>
 

Parameters:
key - The value from the input element in the form
Returns:
The String value for the given key

getSelected

public java.lang.String getSelected(java.lang.String key)
Retrieve a choice from the map: should be used in an option for a selection list element.

Access this from the HTML option for the select element
Assume that rec is a record object whose class extends this class, and that heat is an option in a multiple selection list.

 <option value="heat" rec.getSelected("heat")>
 

Parameters:
key - The value from the input element in the form
Returns:
The String value for the given key

setChoice

public void setChoice(java.lang.String key,
                      java.lang.String value)
Set a choice in the map: the type is either "checked" or "selected". This will be the word associated with this entry in the map.

Usually called with value(s) from the query string
Assume that rec is a record object whose class extends this class, and that color is a radio group.

 rec.setChoice(request.getParamter("color"), "checked");
 
Call this once for each radio or checkbox group, or selection list
Call it before calling any of the get methods from this class.

Parameters:
key - The value from the query string
value - Either "checked" or "seleted"

setChoice

public void setChoice(java.lang.String[] keys,
                      java.lang.String value)
Set a choice in the map: the type is either "checked" or "selected". This will be the word associated with these entries in the map.

Usually called with value(s) from the query string
Assume that rec is a record object whose class extends this class, and that team is a checkbox group.

 rec.setChoice(request.getParamterValues("team"), "checked");
 
Call this once for each radio group, checkbox group or selection list
Call it before calling any of the get methods from this class.

Parameters:
keys - The array of values from the query string
value - Either "checked" or "seleted"

setChecked

public void setChecked(java.lang.String key)
Set a type of "checked" for this entry in the map.

Usually called with value(s) from the query string
Assume that rec is a record object whose class extends this class, and that color is a radio group.

 rec.setChecked(request.getParamter("color"));
 
Call this once for each radio or checkbox group
Call it before calling any of the get methods from this class.

Parameters:
key - The value from the query string

setChecked

public void setChecked(java.lang.String[] keys)
Set a type of "checked" for an array of String keys.

Usually called with value(s) from the query string
Assume that rec is a record object whose class extends this class, and that team is a checkbox group.

 rec.setChecked(request.getParamterValues("team"));
 
Call this once for each radio group, checkbox group
Call it before calling any of the get methods from this class.

Parameters:
keys - The array of values from the query string

setSelected

public void setSelected(java.lang.String key)
Set a type of "selected" for this entry in the map.

Usually called with value(s) from the query string
Assume that rec is a record object whose class extends this class, and that color is a single selection list.

 rec.setSelected(request.getParamter("color"));
 
Call this once for each selection list
Call it before calling any of the get methods from this class.

Parameters:
key - The value from the query string

setSelected

public void setSelected(java.lang.String[] keys)
Set a type of "selected" for an array of String keys.

Usually called with value(s) from the query string
Assume that rec is a record object whose class extends this class, and that team is a multiple selection list.

 rec.setSelected(request.getParamterValues("team"));
 
Call this once for each selection list.
Call it before calling any of the get methods from this class.

Parameters:
keys - The array of values from the query string