|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.locomotive.loco.FormData
FormData combines the features of a Hashtable with a string-checker and a StringBuffer into one powerful class. FormData allows you to get the values of the fields in a form, check whether those values fit a specific format, and generate automatic error messages when those values do not fit the format. You do not need to create an instance of FormData, if you use the GenericRequest class. The constructor for GenericRequest automatically instantiates a local variable called form_data, which is an instance of FormData that has been filled out with the form values from the Web browser. There is extensive documentation about how to use the FormData class, in Chapter III of the Locomotive Developer's Guide. However, we will present a few examples here. In general, you can use the methods whose names start with get...() to retrieve the values of fields. For example:
String username = form_data.getAlphanum ("LOGIN_USERNAME", "username", 2, 12, true);In general, all the get...() methods have the same five arguments:
boolean too_short = form_data.hasError(FormData.TOO_SHORT); String too_short_message = form_data.lastErrorMsg(FormData.TOO_SHORT);You can override the error message that was generated for a particular error code during the last get...() method call, using setErrorMsg(...). Or, if you want to ignore an error code, use ignoreErrorCode(...). If you want to see the sum total of all error messages generated for all fields, use allErrorMsgs().
Field Summary | |
static int |
DOESNT_FIT_TYPE
|
static int |
IS_EMPTY
|
static int |
IS_NULL
|
static int |
NO_ERROR
|
static int |
TOO_LARGE
|
static int |
TOO_LONG
|
static int |
TOO_SHORT
|
static int |
TOO_SMALL
|
Constructor Summary | |
FormData(java.util.Hashtable form_hash)
create a new FormData object, and initialize it with the values of the fields from the Hashtable, form_hash. |
Method Summary | |
java.lang.String |
allErrorMsgs()
returns a String containing all the error messages generated while accessing all the fields in this form. |
boolean |
containsAll(java.lang.String[] names_of_all_fields)
tells whether the form contains values for all of the fields mentioned. |
boolean |
containsAllNonEmpty(java.lang.String[] names_of_all_fields)
tells whether the form contains non-empty values for all of the fields mentioned. |
void |
copyAllIntoSteam(java.util.Hashtable steam_variables)
copies the values of all fields in this form to the Hashtable containing all the Steam variables, so that you can use the Steam variables to put in default values for the form fields in the HTML template. |
java.lang.String |
getAlphanum(java.lang.String field_name,
java.lang.String name_to_display,
int minimum_length,
int maximum_length,
boolean warn_non_alphanum)
if this field contains non_alphanumerics, then they will be removed. |
java.util.Date |
getDate(java.lang.String field_name,
java.lang.String name_to_display)
tries to parse a field as a Date in one of the following formats: "MMM d, yyyy", "MM-d-yy", "MM-d-yyyy", "MM/d/yy", "MM/d/yyyy", "d.MM.yy", "d.MM.yyyy". |
java.util.Date |
getDate(java.lang.String month_field,
java.lang.String day_field,
java.lang.String year_field,
java.lang.String name_to_display)
tries to parse the three fields, month_field, day_field, and year_field, and create a Date out of them. |
java.lang.String |
getDigits(java.lang.String field_name,
java.lang.String name_to_display,
int minimum_length,
int maximum_length,
boolean warn_non_digits)
if this field contains non-digits, then the non-digits will be removed. |
java.lang.String |
getEmailAddress(java.lang.String field_name,
java.lang.String name_to_display,
int minimum_length,
int maximum_length)
Will return the email address no matter what, even if it doesn't fit, but if there are errors, will give IS_NULL, IS_EMPTY, TOO_SHORT, TOO_LONG, and DOESNT_FIT_TYPE. |
java.lang.String |
getField(java.lang.String field_name)
returns the value of the field named field_name. |
java.util.Hashtable |
getHashtable()
returns the value of a Hashtable containing all fields in this form. |
int |
getInt(java.lang.String field_name,
java.lang.String name_to_display)
tries to read a field as an int. |
int |
getIntWithinBounds(java.lang.String field_name,
java.lang.String name_to_display,
int minimum,
int maximum)
tries to read a field as an int, bounded by a minimum and a maximum. |
java.lang.String |
getNonEmptyField(java.lang.String field_name,
java.lang.String name_to_display)
returns the value of the field named field_name. |
java.lang.String |
getNonNullField(java.lang.String field_name,
java.lang.String name_to_display)
returns the value of the field named field_name. |
java.lang.String |
getString(java.lang.String field_name,
java.lang.String name_to_display,
int minimum_length,
int maximum_length)
Returns the string field named field_name. |
java.lang.String |
getTrimmedString(java.lang.String field_name,
java.lang.String name_to_display,
int minimum_length,
int maximum_length)
This method trims the leading and trailing whitespace in a field, and returns its value. |
boolean |
hasAnyErrors()
tells whether the last get...() method generated any errors of any kind. |
boolean |
hasError(int error_code)
tells whether the last get...() method generated an error whose code matches error_code. |
void |
ignoreErrorCode(int error_code)
allows you to ignore the error message associated with error_code in the last get...() method call. |
void |
ignoreErrors()
allows you to ignore all the error messages in the last get...() method call. |
boolean |
isEmpty()
tells whether the form is empty (contains no fields). |
java.lang.String |
lastErrorMsg(int error_code)
if the last get...() method generated an error matching error_code, this method will return the error message. |
void |
setMsgForError(int error_code,
java.lang.String error_msg)
allows you to set the error message for a particular error code. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int NO_ERROR
public static final int IS_NULL
public static final int IS_EMPTY
public static final int TOO_SHORT
public static final int TOO_LONG
public static final int TOO_SMALL
public static final int TOO_LARGE
public static final int DOESNT_FIT_TYPE
Constructor Detail |
public FormData(java.util.Hashtable form_hash)
Method Detail |
public java.lang.String getField(java.lang.String field_name)
public java.util.Hashtable getHashtable()
public boolean isEmpty()
public void copyAllIntoSteam(java.util.Hashtable steam_variables)
public boolean containsAll(java.lang.String[] names_of_all_fields)
String[] required_fields = { "USERNAME", "USERID", ... }; boolean is_good = my_form.containsAll(required_fields);
public boolean containsAllNonEmpty(java.lang.String[] names_of_all_fields)
public java.lang.String getNonNullField(java.lang.String field_name, java.lang.String name_to_display)
public java.lang.String getNonEmptyField(java.lang.String field_name, java.lang.String name_to_display)
public boolean hasError(int error_code)
public boolean hasAnyErrors()
public java.lang.String lastErrorMsg(int error_code)
public void setMsgForError(int error_code, java.lang.String error_msg)
public java.lang.String allErrorMsgs()
public void ignoreErrorCode(int error_code)
public void ignoreErrors()
public int getInt(java.lang.String field_name, java.lang.String name_to_display)
field_name
- the name of the int field in the form.name_to_display
- the name to display in an error message to the user.
May generate the errors IS_NULL, IS_EMPTY, and DOESNT_FIT_TYPE.public int getIntWithinBounds(java.lang.String field_name, java.lang.String name_to_display, int minimum, int maximum)
field_name
- the name of the int field in the form.name_to_display
- the name to display in an error message to the user.minimum
- the minimum this number can be.maximum
- the maximum this number can be.
May generate the errors IS_NULL, IS_EMPTY, DOESNT_FIT_TYPE,
TOO_SMALL, and TOO_LARGE.public java.lang.String getDigits(java.lang.String field_name, java.lang.String name_to_display, int minimum_length, int maximum_length, boolean warn_non_digits)
public java.lang.String getAlphanum(java.lang.String field_name, java.lang.String name_to_display, int minimum_length, int maximum_length, boolean warn_non_alphanum)
public java.lang.String getString(java.lang.String field_name, java.lang.String name_to_display, int minimum_length, int maximum_length)
public java.lang.String getTrimmedString(java.lang.String field_name, java.lang.String name_to_display, int minimum_length, int maximum_length)
public java.util.Date getDate(java.lang.String field_name, java.lang.String name_to_display)
public java.util.Date getDate(java.lang.String month_field, java.lang.String day_field, java.lang.String year_field, java.lang.String name_to_display)
public java.lang.String getEmailAddress(java.lang.String field_name, java.lang.String name_to_display, int minimum_length, int maximum_length)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |