Introduction


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:


reset( )

Prepares an ActionForm to receive data from an HTTP request. This method primarily serves as a place for you to reset checkbox properties.


validate( )

Performs data validation on ActionForm properties before the data is sent to your Action.

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.



    Jakarta Struts Cookbook
    Jakarta Struts Cookbook
    ISBN: 059600771X
    EAN: 2147483647
    Year: 2005
    Pages: 200

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net