Chapter 5. Processing Forms
Introduction
ActionForm
s are key
components of any Struts application. They transport data between the
Controller—that is, your Actions—and
the View—your JSP pages. They protect your business layer
components by acting as a firewall; they only let in expected data
received from the HTTP request.
An
ActionForm is a
JavaBean that extends the
org.apache.struts.ActionForm
class. ActionForms declare properties that
correlate to form fields and data displayed on a presentation page
using getter (getXXX( )) and setter
(setXXX( )) methods. An
ActionForm can override two additional methods
that the Struts framework calls when processing a servlet request:
-
reset( ) Prepares an
ActionFormto receive data from an HTTP request. This method primarily serves as a place for you to reset checkbox properties.-
validate( ) Performs data validation on
ActionFormproperties before the data is sent to yourAction.
In addition to providing JavaBean-style properties that accept HTTP
request data, the ActionForm can contain
additional data that don't directly correspond to an
HTML input field. This data could be used directly on the HTML form,
such as the options displayed in an HTML select (drop-down) control.
Typically, these "extra"
ActionForm data provide contextual information for
the form being displayed. Many developers prefer to use the
ActionForm as the JavaBean that provides
all data for a page: the properties on the form and properties for ancillary data. Others prefer ...