|
ActionForms are key components of any Struts application. They transport data between the Controllerthat is, your Actionsand the Viewyour 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:
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 to keep the ActionForm focused on providing only the properties needed to support the form. In this latter approach, the JSP page accesses the ancillary data through other scoped variables external to the ActionForm. Both of these approaches are valid and acceptable. Either way, understanding the different types of ActionForms, how they work, and how to use them will make your Struts development go a lot smoother. |
|