org.formproc
Class Form

java.lang.Object
  |
  +--org.formproc.Form
Direct Known Subclasses:
ExtendedHttpForm, HttpForm

public class Form
extends java.lang.Object

A form represents a collection of fields which can be validated. Every form has a name which corresponds to a form definition in the formproc.xml file. In addition every form has a target object. When a form is processed each field is written to the target object either through a setxxx() method or through a method defined in the form's XML configuration file.

Author:
Anthony Eden

Field Summary
protected  ValidationResultMap validationResults
           
 
Constructor Summary
Form()
          Construct a new form.
Form(java.lang.String name, java.lang.Object target)
          Construct a new form with the given form name and target object.
 
Method Summary
 void configure(FormConfiguration formConfiguration)
          Configure this form from the given FormConfiguration.
protected  java.lang.Object convert(FormElement formElement, java.lang.Object value, java.util.Locale locale)
          Convert the given value from one type to another using the converter assigned to the given FormElement.
 java.lang.String getErrorMessage(java.lang.String name)
          Get the last error message for the given field.
 java.lang.String getErrorMessage(java.lang.String name, java.util.Locale locale)
          Get the last error message for the given field using the given Locale.
protected  FormConfiguration getFormConfiguration()
          Get the FormConfiguration for this form.
 java.lang.String getMessage(java.lang.String name)
          Get a message for the given field using the default Locale.
 java.lang.String getMessage(java.lang.String name, java.util.Locale locale)
          Get a message for the given field using the given Locale.
 java.lang.String getName()
          Get the form name.
 java.lang.Object getTarget()
          Get the target object.
 java.lang.String getWriteMethod(java.lang.String name)
          Get the write method for the given field name.
 FormResult process(FormData[] formData)
          Process the given FormData objects.
 FormResult process(FormData[] formData, java.util.Locale locale)
          Process the given FormData objects.
protected  ValidationResult process(FormElement formElement, FormData formData, java.util.Locale locale)
          Process the given FormData object.
 FormResult process(java.util.List formData)
          Process the given FormData objects.
 FormResult process(java.util.List formData, java.util.Locale locale)
          Process the given FormData objects.
 void setName(java.lang.String name)
          Set the form name.
 void setTarget(java.lang.Object target)
          Set the target object.
protected  void store(FormElement formElement, java.lang.Object value, java.util.Locale locale)
          Store the value for the named field in the target object.
protected  ValidationResult validate(FormElement formElement, FormData formData, java.util.Locale locale)
          Validate the given form data.
protected  ValidationResultMap validateGroups(FormData[] formData, java.util.Locale locale)
          Validate all of the FormElementGroups defined for this form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

validationResults

protected ValidationResultMap validationResults
Constructor Detail

Form

public Form()
Construct a new form.


Form

public Form(java.lang.String name,
            java.lang.Object target)
Construct a new form with the given form name and target object.

Parameters:
name - The form name
target - The target object
Method Detail

getName

public java.lang.String getName()
Get the form name.

Returns:
The form name

setName

public void setName(java.lang.String name)
Set the form name. The form name given here should match the form name specified in the configuration file.

Parameters:
name - The form name

getTarget

public java.lang.Object getTarget()
Get the target object.

Returns:
The target object

setTarget

public void setTarget(java.lang.Object target)
Set the target object.

Parameters:
target - The target object

getMessage

public java.lang.String getMessage(java.lang.String name)
Get a message for the given field using the default Locale. If the field is not found then this method returns an empty String.

Parameters:
name - The field name
Returns:
The message

getMessage

public java.lang.String getMessage(java.lang.String name,
                                   java.util.Locale locale)
Get a message for the given field using the given Locale. If the field is not found then this method returnes an empty String.

Parameters:
name - The field name
locale - The Locale
Returns:
The message

getErrorMessage

public java.lang.String getErrorMessage(java.lang.String name)
Get the last error message for the given field. If no error message is found then this method returns an empty String.

Parameters:
name - The field name
Returns:
The error message

getErrorMessage

public java.lang.String getErrorMessage(java.lang.String name,
                                        java.util.Locale locale)
Get the last error message for the given field using the given Locale. If there is no error message then this method returns an empty String.

Parameters:
name - The field name
locale - The Locale
Returns:
The error message

getWriteMethod

public java.lang.String getWriteMethod(java.lang.String name)
Get the write method for the given field name. This method will first look for an explicit write method specified in the XML configuration file. If no explicit method is found or the form field is not defined in the configuration then a setxxx() method will be used, where xxx is the field name with the first letter capitalized.

For example: given a field called address and no defined write method, the method will be setAddress. Given a field firstName, the write method is setFirstName. Given a field firstname, the write method is setFirstname.

Parameters:
name - The field name
Returns:
The write method

configure

public void configure(FormConfiguration formConfiguration)
Configure this form from the given FormConfiguration. This method will not normally be called directly, rather the Form object should be passed to the FormManager.configure() method.

Parameters:
formConfiguration - The FormConfiguration

process

public FormResult process(FormData[] formData)
                   throws java.lang.Exception
Process the given FormData objects. This method uses the default Locale.

Parameters:
formData - An array of FormData objects
Returns:
The FormResult object
Throws:
java.lang.Exception - Any exception

process

public FormResult process(FormData[] formData,
                          java.util.Locale locale)
                   throws java.lang.Exception
Process the given FormData objects.

Parameters:
formData - An array of FormData objects
locale - The current locale
Returns:
The FormResult object
Throws:
java.lang.Exception - Any exception

process

public FormResult process(java.util.List formData)
                   throws java.lang.Exception
Process the given FormData objects.

Parameters:
formData - An List of FormData objects
Returns:
The FormResult object
Throws:
java.lang.Exception - Any exception

process

public FormResult process(java.util.List formData,
                          java.util.Locale locale)
                   throws java.lang.Exception
Process the given FormData objects.

Parameters:
formData - An List of FormData objects
locale - The current locale
Returns:
The FormResult object
Throws:
java.lang.Exception - Any exception

process

protected ValidationResult process(FormElement formElement,
                                   FormData formData,
                                   java.util.Locale locale)
                            throws java.lang.Exception
Process the given FormData object. The FormData object will first be validated and then stored in the target object by invoking the setXXX method for the given field.

Parameters:
formData - The FormData object
Returns:
The ValidationResult
Throws:
java.lang.Exception - Any exception

validate

protected ValidationResult validate(FormElement formElement,
                                    FormData formData,
                                    java.util.Locale locale)
                             throws java.lang.Exception
Validate the given form data.

Parameters:
formElement - The FormElement
formData - The form data
locale - The Locale
Returns:
The ValidationResult
Throws:
java.lang.Exception - Any exception

validateGroups

protected ValidationResultMap validateGroups(FormData[] formData,
                                             java.util.Locale locale)
                                      throws java.lang.Exception
Validate all of the FormElementGroups defined for this form. The given FormData array will be filtered for each group so that each group's validator receives only the values for elements which are in the group.

Parameters:
formData - The FormData array
locale - The Locale
Returns:
The ValidationResultMap
Throws:
java.lang.Exception

convert

protected java.lang.Object convert(FormElement formElement,
                                   java.lang.Object value,
                                   java.util.Locale locale)
                            throws java.lang.Exception
Convert the given value from one type to another using the converter assigned to the given FormElement.

Parameters:
formElement - The FormElement
value - The value
locale - The locale
Returns:
The new typed object
Throws:
java.lang.Exception - Any exception

store

protected void store(FormElement formElement,
                     java.lang.Object value,
                     java.util.Locale locale)
              throws java.lang.Exception
Store the value for the named field in the target object. Subclasses can override this method to change the store behavior.

Parameters:
formElement - The FormElement
value - The value
locale - The locale
Throws:
java.lang.Exception - Any exception

getFormConfiguration

protected FormConfiguration getFormConfiguration()
Get the FormConfiguration for this form.

Returns:
The FormConfiguration


Copyright (c) 2001-2003 Anthony Eden. All Rights Reserved.