|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.perdues.web.HTForm
This class is sort of modeled after Perl's CGI.pm. It gives you a bunch of methods that render HTML form elements with the state maintained. In addition you can set the state of a field, which you can't do easily with HttpServletRequest itself.
HTForm has a HttpServletRequest object, and consults that when rendering a form element. So you can use it in any case you would have used HttpServletRequest.getParameterValues()
The database operations use extended database schema information from the com.perdues.db.Schema class.
Constructor Summary | |
HTForm()
Construct an empty Form. |
|
HTForm(HTForm form)
Construct a copy of an existing HTForm. |
|
HTForm(javax.servlet.http.HttpServletRequest request)
A form gets its initial state from the parameters in the request. |
Method Summary | |
void |
addValue(java.lang.String fieldname,
java.lang.String value)
Adds the given value to the list of values for the given field name if not already in the list. |
java.lang.String |
getCheckbox(java.lang.String fieldname)
Renders a single checkbox with the given field name and the value "y" when checked. |
java.lang.String |
getCheckbox(java.lang.String fieldname,
java.lang.String value)
Renders a single checkbox with the given field name and value when checked. |
java.lang.String |
getCheckboxes(java.lang.String fieldname,
java.lang.String[] values)
Renders a list of checkboxes, all with the same field name, with the values and labels the same, as if with an empty hash table in the variant with a hash table argument. |
java.lang.String |
getCheckboxes(java.lang.String field,
java.lang.String[] values,
java.util.Hashtable labels)
Renders a list of checkboxes, all with the same field name, one for each value in the list. |
java.lang.String |
getChoice(java.lang.String fieldname,
java.lang.String[] values)
Render a choice (dropdown list) for the named field with the listed values. |
java.lang.String |
getChoice(java.lang.String fieldname,
java.lang.String[] values,
java.util.Hashtable labels)
Render a choice (dropdown list) for the named field with the listed values. |
java.util.Date |
getDate(java.lang.String fieldname)
Reconstructs a date from the three shadow fields. |
java.lang.String |
getDateField(java.lang.String fieldname,
int start_year,
int stop_year)
|
java.lang.String |
getHidden(java.lang.String fieldname)
Returns a set of <input type="hidden"> HTML form fields with the values properly set. |
int |
getInt(java.lang.String fieldname)
Returns the value of the given field as an integer, throwing a NumberFormatException if the value does not represent an integer, as determined by Integer.parseInt. |
int |
getInt(java.lang.String fieldname,
int dfault)
Returns the value of the given field as an integer, returning the given defaultvalue if the value does not represent an intger as determined by Integer.parseInt. |
java.lang.String |
getList(java.lang.String fieldname,
int size,
boolean allowMultiple,
java.lang.String[] values)
Render a scrolling list for the named field and values, with the specified size in rows, and allowing multiple selection if allowMultiple is true. |
java.lang.String |
getList(java.lang.String fieldname,
int size,
boolean allowMultiple,
java.lang.String[] values,
java.util.Hashtable labels)
Render a scrolling list for the named field and values, with the specified size in rows, and allowing multiple selection if allowMultiple is true. |
java.lang.String |
getOptions(java.lang.String fieldname,
java.lang.String[] values,
java.util.Hashtable labels)
Return a list of option tags for an HTML select. |
java.lang.String |
getPassword(java.lang.String fieldname,
int size,
int maxlength)
Returns a <input type="password"> HTML form element with the state maintained |
java.lang.String |
getRadios(java.lang.String fieldname,
java.lang.String[] values,
java.util.Hashtable labels)
Renders a list of radio buttons, all with the same field name, one for each value in the list. |
java.lang.String |
getText(java.lang.String text)
Returns the same value, escaped for HTML, and suitably escaped to be inside an HTML attribute (quotes escaped). |
java.lang.String |
getTextarea(java.lang.String fieldname,
int rows,
int cols)
calls getTextarea() with "none" as the wrap attribute. |
java.lang.String |
getTextarea(java.lang.String fieldname,
int rows,
int cols,
java.lang.String wrap)
Returns a <textarea> HTML form element with the state maintained. |
java.lang.String |
getTextfield(java.lang.String fieldname,
int size,
int maxlength)
Returns a <input type="text"> HTML form element with the state maintained |
java.lang.String |
getValue(java.lang.String fieldname)
A shorthand version of getValue(string, boolean) that passes in true as the returnNull parameter. |
java.lang.String |
getValue(java.lang.String fieldname,
boolean returnNull)
Returns the value of a given field. |
java.lang.String |
getValue(java.lang.String fieldname,
java.lang.String defaultValue)
Returns the value of a given field. |
java.lang.String[] |
getValues(java.lang.String fieldname)
Returns the list of values for the given fieldname. |
boolean |
has(java.lang.String fieldname)
Returns true iff getValue(fieldname) would return a string with at least one character in it. |
boolean |
hasValue(java.lang.String fieldname,
java.lang.String value)
True iff the given field of the form has a value equal to the one given. |
java.util.Enumeration |
keys()
Returns an enumeration of all the field names in this HTForm. |
void |
mergeForm(HTForm form,
boolean overwrite)
Copies the contents of form into this form. |
void |
mergePathInfo(boolean overwrite)
Treats PATH_INFO like another QUERY_STRING and folds those values into the form. |
java.lang.Object |
removeValue(java.lang.String key)
Removes the value with the specified key. |
void |
removeValue(java.lang.String fieldname,
java.lang.String value)
Removes any occurrences of the given value from the list of values for fieldname. |
void |
setDate(java.lang.String fieldname,
java.util.Date date)
Sets a SQL-style string and three shadow variables for the date. |
void |
setDefault(java.lang.String fieldname,
java.lang.String value)
Sets the given value if there is none yet for the given field name. |
void |
setValue(java.lang.String fieldname,
java.lang.String value)
Sets value in the given slot fieldname. |
void |
setValues(java.lang.String fieldname,
java.lang.String[] values)
Same as form.setValue() except it sets multiple values from an array of values instead of taking a single value. |
java.lang.String[] |
splitString(java.lang.String str)
Splits "str" into an array of Strings using \r\n as the delimitter. |
java.lang.String |
toQueryString()
Create and return an HTTP query string (without the "?") representing the same field information contained in this HTForm. |
java.lang.String |
toString()
Overridden method from class Object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public HTForm(javax.servlet.http.HttpServletRequest request)
public HTForm()
public HTForm(HTForm form)
Method Detail |
public java.lang.String getValue(java.lang.String fieldname)
public java.lang.String getValue(java.lang.String fieldname, java.lang.String defaultValue)
public int getInt(java.lang.String fieldname)
public int getInt(java.lang.String fieldname, int dfault)
public java.lang.String getValue(java.lang.String fieldname, boolean returnNull)
public boolean has(java.lang.String fieldname)
public boolean hasValue(java.lang.String fieldname, java.lang.String value)
public java.lang.String[] getValues(java.lang.String fieldname)
The only difference between this method and the one in HttpServletRequest is that this will consult a local hash of values first that can be modified by adding, changing, or removing values.
public java.util.Date getDate(java.lang.String fieldname)
public java.lang.String[] splitString(java.lang.String str)
public void setValue(java.lang.String fieldname, java.lang.String value)
public void setValues(java.lang.String fieldname, java.lang.String[] values)
public void addValue(java.lang.String fieldname, java.lang.String value)
public void setDefault(java.lang.String fieldname, java.lang.String value)
public void removeValue(java.lang.String fieldname, java.lang.String value)
public void setDate(java.lang.String fieldname, java.util.Date date)
public java.lang.String toQueryString()
public void mergeForm(HTForm form, boolean overwrite)
public void mergePathInfo(boolean overwrite)
public java.lang.Object removeValue(java.lang.String key)
public java.util.Enumeration keys()
public java.lang.String getText(java.lang.String text)
public java.lang.String getTextfield(java.lang.String fieldname, int size, int maxlength)
public java.lang.String getPassword(java.lang.String fieldname, int size, int maxlength)
public java.lang.String getTextarea(java.lang.String fieldname, int rows, int cols, java.lang.String wrap)
fieldname
- name of textarea to createrows
- number of rows in textareacols
- number of columns in textareawrap
- string to place in wrap="" attribute. valid values
are "none", "virtual", "physical"public java.lang.String getTextarea(java.lang.String fieldname, int rows, int cols)
public java.lang.String getChoice(java.lang.String fieldname, java.lang.String[] values)
public java.lang.String getChoice(java.lang.String fieldname, java.lang.String[] values, java.util.Hashtable labels)
public java.lang.String getList(java.lang.String fieldname, int size, boolean allowMultiple, java.lang.String[] values)
public java.lang.String getList(java.lang.String fieldname, int size, boolean allowMultiple, java.lang.String[] values, java.util.Hashtable labels)
public java.lang.String getOptions(java.lang.String fieldname, java.lang.String[] values, java.util.Hashtable labels)
public java.lang.String getCheckbox(java.lang.String fieldname, java.lang.String value)
public java.lang.String getCheckbox(java.lang.String fieldname)
public java.lang.String getCheckboxes(java.lang.String fieldname, java.lang.String[] values)
public java.lang.String getCheckboxes(java.lang.String field, java.lang.String[] values, java.util.Hashtable labels)
Renders checkboxes checked based on the value or values for the given field in this Form object. Renders each box with a checkmark if its values is equal to some value for the given field in this Form.
public java.lang.String getRadios(java.lang.String fieldname, java.lang.String[] values, java.util.Hashtable labels)
Renders radio buttons checked based on the value for the given field in this Form object. Renders a box with a checkmark if its values is equal to the value for the given field in this Form.
public java.lang.String getHidden(java.lang.String fieldname)
public java.lang.String getDateField(java.lang.String fieldname, int start_year, int stop_year)
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |