com.raj.htmlForms
Class HtmlSelect

java.lang.Object
  |
  +--com.raj.htmlForms.HtmlFormElement
        |
        +--com.raj.htmlForms.HtmlSelect

public class HtmlSelect
extends HtmlFormElement

This class represents the <select> tag of a form. It is a drop down list, with several options. It implements all of the HTML 4.01 Transitional specification.

The population of this drop-down box will come from a data structure containing keys (which act as the value of the <option> tag) and entries which will be the text displayed for that entry.

This class (HtmlSelect.java) is part of the com.raj.htmlForms package that automatically generates HTML forms programmatically.

CREATED 26-FEB-2002, Copyright (c) Rajnish Bhaskar 2002

Author:
Rajnish Bhaskar
See Also:
W3C Reference of the select attribute

Field Summary
 
Fields inherited from class com.raj.htmlForms.HtmlFormElement
isXHTML, out
 
Constructor Summary
HtmlSelect(java.io.Writer w)
          Minimal constructor for any form element.
HtmlSelect(java.io.Writer w, boolean x)
          Constructor that sets the writer and a boolean which determines whether or not XHTML will be written
HtmlSelect(java.io.Writer w, java.lang.String n)
          Constructor that just sets the name of the element
HtmlSelect(java.io.Writer w, java.lang.String n, java.util.Map m)
          Constructor that just sets the name of the element
 
Method Summary
 java.util.Map getEntries()
          return the data structure that will populate the select box
 java.lang.String getMultiple()
          if multiple selection is permitted this is returned, else the empty string
 java.lang.String getOnChange()
          gets the contents of the Javascript onFocus event.
 java.lang.String getSelected()
          returns the value of the option that should be selected by default
 java.lang.String getSize()
          gets the number of rows visible for this select box
 void reset()
          resets all attributes of the element back to a blank state
 void setEntries(java.util.Map x)
          sets the data structure from which the select box will be populated
 void setMultiple(boolean x)
          sets whether or not multiple selection is enabled (note: size must be > 1 for this)
 void setOnChange(java.lang.String x)
          specifies the content of the Javascript onFocus event.
 void setSelected(java.lang.String x)
          stores the option in this select group that should be selected by default
 void setSize(int x)
          sets the number of rows visible for this select box
 java.lang.String toString()
          Writes the attributes of this object to a string and returns them.
 void write()
          writes an HTML drop-down box to the given writer, populated by the given data structure
 
Methods inherited from class com.raj.htmlForms.HtmlFormElement
getDir, getId, getLang, getName, getOnBlur, getOnClick, getOnDblClick, getOnFocus, getOnKeyDown, getOnKeyPress, getOnKeyUp, getOnMouseDown, getOnMouseMove, getOnMouseOut, getOnMouseOver, getOnMouseUp, getOnSelect, getStyle, getTabIndex, getTheClass, getTitle, getXhtml, setDir, setId, setLang, setName, setOnBlur, setOnClick, setOnDblClick, setOnFocus, setOnKeyDown, setOnKeyPress, setOnKeyUp, setOnMouseDown, setOnMouseMove, setOnMouseOut, setOnMouseOver, setOnMouseUp, setOnSelect, setStyle, setStyle, setTabIndex, setTheClass, setTitle, setXhtml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HtmlSelect

public HtmlSelect(java.io.Writer w)
Minimal constructor for any form element. All other attributes can be added by the appropriate setter method. This follows the standard Java convention for attributes, so the attribute foo becomes setFoo(). The attribute names can be found at the W3C HTML reference or many other places on the web.

Parameters:
w - the Writer to which all the data will be written out
See Also:
W3C Reference for forms

HtmlSelect

public HtmlSelect(java.io.Writer w,
                  boolean x)
Constructor that sets the writer and a boolean which determines whether or not XHTML will be written

Parameters:
w - the Writer to which all the data will be written out
x - if true, XHTML will be written, else false

HtmlSelect

public HtmlSelect(java.io.Writer w,
                  java.lang.String n)
Constructor that just sets the name of the element

Parameters:
w - the Writer to which all the data will be written out
n - the name of this element
See Also:
W3C Reference for forms

HtmlSelect

public HtmlSelect(java.io.Writer w,
                  java.lang.String n,
                  java.util.Map m)
Constructor that just sets the name of the element

Parameters:
w - the Writer to which all the data will be written out
n - the name of this element
m - the data structure used to populate this select box
See Also:
W3C Reference for forms
Method Detail

setEntries

public void setEntries(java.util.Map x)
sets the data structure from which the select box will be populated

See Also:
W3C reference of SELECT

getEntries

public java.util.Map getEntries()
return the data structure that will populate the select box


setSize

public void setSize(int x)
sets the number of rows visible for this select box

See Also:
W3C reference of this attribute

getSize

public java.lang.String getSize()
gets the number of rows visible for this select box

See Also:
W3C reference of this attribute

setMultiple

public void setMultiple(boolean x)
sets whether or not multiple selection is enabled (note: size must be > 1 for this)

See Also:
W3C reference of this attribute

getMultiple

public java.lang.String getMultiple()
if multiple selection is permitted this is returned, else the empty string

See Also:
W3C reference of this attribute

setSelected

public void setSelected(java.lang.String x)
stores the option in this select group that should be selected by default

See Also:
W3C reference of this attribute

getSelected

public java.lang.String getSelected()
returns the value of the option that should be selected by default


setOnChange

public void setOnChange(java.lang.String x)
specifies the content of the Javascript onFocus event. Note: If you write code with quotes inside a JS event, it must be single quotes (').

See Also:
W3C reference of this attribute

getOnChange

public java.lang.String getOnChange()
gets the contents of the Javascript onFocus event. Note: If you write code with quotes inside a JS event, it must be single quotes (').

See Also:
W3C reference of this attribute

reset

public void reset()
Description copied from class: HtmlFormElement
resets all attributes of the element back to a blank state

Overrides:
reset in class HtmlFormElement

toString

public java.lang.String toString()
Description copied from class: HtmlFormElement
Writes the attributes of this object to a string and returns them.

The toString() method should logically return a string representing the attributes of the HTML element, eg if you set the name, title and style of the element then you should return a string containing:

name="myName" title="some title" style="foo: xxx; bar: yyy;"

The responsibility for turning this into a form deliverable to a user agent belongs to the write() method.

Overrides:
toString in class HtmlFormElement
See Also:
HtmlFormElement.write()

write

public void write()
writes an HTML drop-down box to the given writer, populated by the given data structure

Specified by:
write in class HtmlFormElement