org.apache.struts.action
Class ActionForm

java.lang.Object
  |
  +--org.apache.struts.action.ActionForm
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ValidatingActionForm

public abstract class ActionForm
extends java.lang.Object
implements java.io.Serializable

An ActionForm is a JavaBean optionally associated with one or more ActionMappings. Such a bean will have had its properties initialized from the corresponding request parameters before the corresonding action's perform() method is called.

When the properties of this bean have been populated, but before the perform() method of the action is called, this bean's validate() method will be called, which gives the bean a chance to verify that the properties submitted by the user are correct and valid. If this method finds problems, it returns an error messages object that encapsulates those problems, and the controller servlet will return control to the corresponding input form. Otherwise, the validate() method returns null(), indicating that everything is acceptable and the corresponding Action's perform() method should be called.

This class must be subclassed in order to be instantiated. Subclasses should provide property getter and setter methods for all of the bean properties they wish to expose, plus override any of the public or protected methods for which they wish to provide modified functionality.

Version:
$Revision: 1.1 $ $Date: 2001/09/17 20:03:01 $
Author:
Craig R. McClanahan
See Also:
Serialized Form

Field Summary
protected  MultipartRequestHandler multipartRequestHandler
          The MultipartRequestHandler for this form, can be null
protected  ActionServlet servlet
          The controller servlet instance to which we are attached.
 
Constructor Summary
ActionForm()
           
 
Method Summary
 MultipartRequestHandler getMultipartRequestHandler()
          Return the MultipartRequestHandler for this form The reasoning behind this is to give form bean developers control over the lifecycle of their multipart requests through the use of the finish() and/or rollback() methods of MultipartRequestHandler.
 ActionServlet getServlet()
          Return the controller servlet instance to which we are attached.
 void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
          Reset all bean properties to their default state.
 void reset(ActionMapping mapping, javax.servlet.ServletRequest request)
          Reset all bean properties to their default state.
 void setMultipartRequestHandler(MultipartRequestHandler multipartRequestHandler)
           
 void setServlet(ActionServlet servlet)
          Set the controller servlet instance to which we are attached (if servlet is non-null), or release any allocated resources (if servlet is null).
 java.lang.String[] validate()
          Deprecated. This is the Struts 0.5 version of validation -- use the validate(ActionMapping,HttpServletRequest) method instead
 ActionErrors validate(ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
          Validate the properties that have been set for this HTTP request, and return an ActionErrors object that encapsulates any validation errors that have been found.
 ActionErrors validate(ActionMapping mapping, javax.servlet.ServletRequest request)
          Validate the properties that have been set for this non-HTTP request, and return an ActionErrors object that encapsulates any validation errors that have been found.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

servlet

protected transient ActionServlet servlet
The controller servlet instance to which we are attached.

multipartRequestHandler

protected transient MultipartRequestHandler multipartRequestHandler
The MultipartRequestHandler for this form, can be null
Constructor Detail

ActionForm

public ActionForm()
Method Detail

getServlet

public ActionServlet getServlet()
Return the controller servlet instance to which we are attached.

getMultipartRequestHandler

public MultipartRequestHandler getMultipartRequestHandler()
Return the MultipartRequestHandler for this form The reasoning behind this is to give form bean developers control over the lifecycle of their multipart requests through the use of the finish() and/or rollback() methods of MultipartRequestHandler. This method will return null if this form's enctype is not "multipart/request-data".
See Also:
MultipartRequestHandler

setServlet

public void setServlet(ActionServlet servlet)
Set the controller servlet instance to which we are attached (if servlet is non-null), or release any allocated resources (if servlet is null).
Parameters:
servlet - The new controller servlet, if any

setMultipartRequestHandler

public void setMultipartRequestHandler(MultipartRequestHandler multipartRequestHandler)

reset

public void reset(ActionMapping mapping,
                  javax.servlet.ServletRequest request)
Reset all bean properties to their default state. This method is called before the properties are repopulated by the controller servlet.

The default implementation attempts to forward to the HTTP version of this method.

Parameters:
mapping - The mapping used to select this instance
request - The servlet request we are processing

reset

public void reset(ActionMapping mapping,
                  javax.servlet.http.HttpServletRequest request)
Reset all bean properties to their default state. This method is called before the properties are repopulated by the controller servlet.

The default implementation does nothing. Subclasses should override this method to reset all bean properties to default values.

Parameters:
mapping - The mapping used to select this instance
request - The servlet request we are processing

validate

public ActionErrors validate(ActionMapping mapping,
                             javax.servlet.ServletRequest request)
Validate the properties that have been set for this non-HTTP request, and return an ActionErrors object that encapsulates any validation errors that have been found. If no errors are found, return null or an ActionErrors object with no recorded error messages.

The default implementation attempts to forward to the HTTP version of this method.

Parameters:
mapping - The mapping used to select this instance
request - The servlet request we are processing

validate

public java.lang.String[] validate()
Deprecated. This is the Struts 0.5 version of validation -- use the validate(ActionMapping,HttpServletRequest) method instead

Perform validations on the form input values included in this form bean. If validation errors occur, return a String array containing the message keys of corresponding error messages (in our application MessageResources) to be displayed. If no validation errors occur, return null.

validate

public ActionErrors validate(ActionMapping mapping,
                             javax.servlet.http.HttpServletRequest request)
Validate the properties that have been set for this HTTP request, and return an ActionErrors object that encapsulates any validation errors that have been found. If no errors are found, return null or an ActionErrors object with no recorded error messages.

The default ipmlementation performs no validation and returns null. Subclasses must override this method to provide any validation they wish to perform.

Parameters:
mapping - The mapping used to select this instance
request - The servlet request we are processing


Copyright © 2000-2001 - Apache Software Foundation