gnu.beanfactory.servlet
Class FormHandler

java.lang.Object
  |
  +--gnu.beanfactory.servlet.FormHandler

public abstract class FormHandler
extends java.lang.Object

FormHandler is an abstract base class that provides a standard mechanism for processing HTML form input. This class provides facilities for form field validation and handling exceptions. Classes that extend FormHandler should be declared as either "session" or "request" scoped. A typical implementation would:

Version:
$Id: FormHandler.java,v 1.12 2001/10/18 04:52:38 rschoening Exp $

Field Summary
 java.lang.String myMessage
           
 
Constructor Summary
FormHandler()
           
 
Method Summary
 void forward(java.lang.String s)
          Convenience method to forward the request to a local resource.
 void forwardToFormErrorURL()
          Convenience method to forward the request to the proper page.
 void forwardToNextURL()
          Convenience method to forward the request to the proper page.
 void forwardToPrevURL()
          Convenience method to forward the request to the proper page.
 java.lang.String getError(java.lang.String prop)
           
 java.lang.String getErrorMessage()
           
 java.lang.String getFormErrorURL()
          URL that the FormHandler should redirect to if there is a form error.
 java.lang.String getMessage()
          A simple property to store a message.
 java.lang.String getNextURL()
           
 org.apache.oro.text.perl.Perl5Util getPerl5Util()
          Convenience method to get an instance of the ORO Perl Regex engine.
 java.lang.String getPrevURL()
           
 javax.servlet.http.HttpServletRequest getRequest()
          A convenience method to obtain the current ServletRequest.
 javax.servlet.http.HttpServletResponse getResponse()
          A convenience method to obtain the current ServletResponse.
 boolean isValid()
          Checks to see if this instance has any form errors.
 void postSet()
          This method gets invoked after the setXXX() methods are called but before the handleXXXX() methods are invoked.
 void preSet()
          This method gets invoked before setXXX() methods are called.
 void putError(java.lang.String property, java.lang.String code)
          Adds a form error to list of form errors.
 void resetErrors()
          Remove all form errors from this FormHandler.
 void setErrorMessage(java.lang.String s)
           
 void setFormErrorURL(java.lang.String url)
          URL that the FormHandler should redirect to if there is a form error.
 void setMessage(java.lang.String s)
          A simple property to store a text message.
 void setNextURL(java.lang.String url)
           
 void setPrevURL(java.lang.String url)
           
abstract  boolean validate()
          All subclasses must implement this method.
 boolean validate(boolean expr, java.lang.String property, java.lang.String code)
          Asserts that a particular boolean expression is true, and adds a form error if it is not.
 boolean validate(java.lang.String regex, java.lang.String input, java.lang.String property, java.lang.String code)
          Validates a form field via a regular expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myMessage

public java.lang.String myMessage
Constructor Detail

FormHandler

public FormHandler()
Method Detail

getPerl5Util

public org.apache.oro.text.perl.Perl5Util getPerl5Util()
Convenience method to get an instance of the ORO Perl Regex engine.

putError

public void putError(java.lang.String property,
                     java.lang.String code)
Adds a form error to list of form errors.
Parameters:
property - name of the bean property that has an error
code - a user-defined error code that identifies the error

getError

public java.lang.String getError(java.lang.String prop)

getMessage

public java.lang.String getMessage()
A simple property to store a message.

setMessage

public void setMessage(java.lang.String s)
A simple property to store a text message.

setErrorMessage

public void setErrorMessage(java.lang.String s)

getErrorMessage

public java.lang.String getErrorMessage()

resetErrors

public void resetErrors()
Remove all form errors from this FormHandler. This is useful for session-scoped FormHandlers which need to have errors from previous HTTP requests reset.

validate

public boolean validate(boolean expr,
                        java.lang.String property,
                        java.lang.String code)
Asserts that a particular boolean expression is true, and adds a form error if it is not.

isValid

public boolean isValid()
Checks to see if this instance has any form errors.
Returns:
True, if putError() has been called

validate

public boolean validate(java.lang.String regex,
                        java.lang.String input,
                        java.lang.String property,
                        java.lang.String code)
Validates a form field via a regular expression. This is the preferred method to validate fields. It is much more concise than using Java string functions.
Parameters:
regular - expression in perl5 syntax
input - the string to be tested (null values are converted to "")
property - the name of the JavaBean property
code - the user defined code for the error (EMPTY, INVALID_DATE, etc.)
Returns:
true, if the validation was successful

getFormErrorURL

public java.lang.String getFormErrorURL()
URL that the FormHandler should redirect to if there is a form error.

setFormErrorURL

public void setFormErrorURL(java.lang.String url)
URL that the FormHandler should redirect to if there is a form error.

getPrevURL

public java.lang.String getPrevURL()

setPrevURL

public void setPrevURL(java.lang.String url)

getNextURL

public java.lang.String getNextURL()

setNextURL

public void setNextURL(java.lang.String url)

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
                                                 throws javax.servlet.ServletException
A convenience method to obtain the current ServletRequest.

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
                                                   throws javax.servlet.ServletException
A convenience method to obtain the current ServletResponse.

forwardToFormErrorURL

public void forwardToFormErrorURL()
                           throws javax.servlet.ServletException
Convenience method to forward the request to the proper page.

forwardToNextURL

public void forwardToNextURL()
                      throws javax.servlet.ServletException
Convenience method to forward the request to the proper page.

forwardToPrevURL

public void forwardToPrevURL()
                      throws javax.servlet.ServletException
Convenience method to forward the request to the proper page.

forward

public void forward(java.lang.String s)
             throws javax.servlet.ServletException
Convenience method to forward the request to a local resource.

preSet

public void preSet()
This method gets invoked before setXXX() methods are called.

postSet

public void postSet()
             throws javax.servlet.ServletException,
                    java.io.IOException
This method gets invoked after the setXXX() methods are called but before the handleXXXX() methods are invoked.

validate

public abstract boolean validate()
All subclasses must implement this method. It should validate the form fields. The return value should ALWAYS be the value of isValid().