Class ActionForm
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DynaActionForm
,ValidatorForm
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
corresponding Action.execute
method is called.
When the properties of this bean have been populated, but before the
execute
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.execute
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.
Because ActionForms are JavaBeans, subclasses should also implement
Serializable
, as required by the JavaBean specification. Some
containers require that an object meet all JavaBean requirements in order
to use the introspection API upon which ActionForms rely.
- Version:
- $Rev$ $Date: 2005-11-12 08:14:24 -0500 (Sat, 12 Nov 2005) $
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected MultipartRequestHandler
The MultipartRequestHandler for this form, can benull
.protected ActionServlet
The servlet instance to which we are attached. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturn theMultipartRequestHandler
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 thefinish
and/orrollback
methods ofMultipartRequestHandler
.protected ActionServlet
Return the servlet instance to which we are attached.Return the controller servlet instance to which we are attached.void
reset
(ActionMapping mapping, HttpServletRequest request) Can be used to reset bean properties to their default state, as needed.void
reset
(ActionMapping mapping, ServletRequest request) Can be used to reset all bean properties to their default state.void
setMultipartRequestHandler
(MultipartRequestHandler multipartRequestHandler) Set the Handler provided for use in dealing with file uploads.void
setServlet
(ActionServlet servlet) Set the servlet instance to which we are attached (ifservlet
is non-null).validate
(ActionMapping mapping, HttpServletRequest request) Can be used to validate the properties that have been set for this HTTP request, and return anActionErrors
object that encapsulates any validation errors that have been found.validate
(ActionMapping mapping, ServletRequest request) Can be used to validate the properties that have been set for this non-HTTP request, and return anActionErrors
object that encapsulates any validation errors that have been found.
-
Field Details
-
servlet
The servlet instance to which we are attached.
-
multipartRequestHandler
The MultipartRequestHandler for this form, can be
null
.
-
-
Constructor Details
-
ActionForm
public ActionForm()
-
-
Method Details
-
getServlet
Return the servlet instance to which we are attached.
- Returns:
- The servlet instance to which we are attached.
-
getServletWrapper
Return the controller servlet instance to which we are attached. as an
ActionServletWrapper
.- Returns:
- An instance of
ActionServletWrapper
- Since:
- Struts 1.0.1
- See Also:
-
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 thefinish
and/orrollback
methods ofMultipartRequestHandler
. This method will returnnull
if this form's enctype is not "multipart/form-data".- Returns:
- The
MultipartRequestHandler
for this form. - See Also:
-
setServlet
Set the servlet instance to which we are attached (if
servlet
is non-null).- Parameters:
servlet
- The new controller servlet, if any
-
setMultipartRequestHandler
Set the Handler provided for use in dealing with file uploads.
- Parameters:
multipartRequestHandler
- The Handler to use for fileuploads.
-
reset
Can be used to reset all bean properties to their default state. This method is called before the properties are repopulated by the controller.
The default implementation attempts to forward to the HTTP version of this method.
- Parameters:
mapping
- The mapping used to select this instancerequest
- The servlet request we are processing
-
reset
Can be used to reset bean properties to their default state, as needed. This method is called before the properties are repopulated by the controller.
The default implementation does nothing. In practice, the only properties that need to be reset are those which represent checkboxes on a session-scoped form. Otherwise, properties can be given initial values where the field is declared.
If the form is stored in session-scope so that values can be collected over multiple requests (a "wizard"), you must be very careful of which properties, if any, are reset. As mentioned, session-scope checkboxes must be reset to false for any page where this property is set. This is because the client does not submit a checkbox value when it is clear (false). If a session-scoped checkbox is not proactively reset, it can never be set to false.
This method is not the appropriate place to initialize form value for an "update" type page (this should be done in a setup Action). You mainly need to worry about setting checkbox values to false; most of the time you can leave this method unimplemented.
- Parameters:
mapping
- The mapping used to select this instancerequest
- The servlet request we are processing
-
validate
Can be used to 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, returnnull
or anActionErrors
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 instancerequest
- The servlet request we are processing- Returns:
- The set of validation errors, if validation failed; an empty
set or
null
if validation succeeded.
-
validate
Can be used to 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, returnnull
or anActionErrors
object with no recorded error messages.The default implementation 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 instancerequest
- The servlet request we are processing- Returns:
- The set of validation errors, if validation failed; an empty
set or
null
if validation succeeded. - See Also:
-