? patch Index: doc/userGuide/building_controller.xml =================================================================== RCS file: /home/cvspublic/jakarta-struts/doc/userGuide/building_controller.xml,v retrieving revision 1.23 diff -u -r1.23 building_controller.xml --- doc/userGuide/building_controller.xml 27 Jul 2002 21:53:13 -0000 1.23 +++ doc/userGuide/building_controller.xml 4 Sep 2002 15:36:28 -0000 @@ -7,6 +7,7 @@ Ted Husted Martin Cooper Ed Burns + Donald Ball The Struts User's Guide - Building Controller Components @@ -90,11 +91,92 @@
-

[:TODO:]

+

Maintaining a separate concrete ActionForm class for each form in your struts application is time-consuming. This can be alleviated through the use of DynaActionForm classes. Instead of creating a new ActionForm subclass and new get/set methods for each of your bean's properties, you can list its properties, type, and defaults in the struts configuration file.

+

For example, add the following to struts-config.xml for a UserForm bean that stores a user's given and family names:

+
+
+  
+  
+
+]]>
+
+

The list of types supported by DynaActionForm beans includes:

+ +

If you do not supply an initial attribute, numbers will be initialized to 0 and objects to null.

-
-

[:TODO:]

+
+

The DynaActionForm classes offer the ability to create ActionForm beans at initialization time, based on a list of properties enumerated in the struts configuration file. However, many HTML forms are generated dynamically at request time. Since the properties of these forms' ActionForm beans are not all known ahead of time, we need a new approach.

+

Struts allows you to make one or more of your ActionForm's properties' values a Map instead of a traditional atomic object. You can then store the data from your form's dynamic fields in that Map. Here is an example of a map-backed ActionForm class:

+
+
+
+

In its corresponding JSP page, you can access objects stored in the values map using a special notation: mapname(keyname). The parentheses in the bean property name indicate that the bean property named mapname is indexed using Strings (probably backed by a Map) and that struts should look for get/set methods that take a String key parameter to find the correct sub-property value. Struts will, of course, use the keyname value from the parentheses when it calls the get/set methods.

+

Here is a simple example:

+
+
+]]>
+
+

This will call the getValue() method on FooForm with a key value of "foo" to find the property value. To create a form with dynamic field names, you could do the following:

+
+"/>
+%> +]]> +
+

Note that there is nothing special about the name value. Your map-backed property could instead be named property, thingy, or any other bean property name you prefer. You can even have multiple map-backed properties on the same bean.

+

In addition to map-backed properties, you can also create list-backed properties. You do so by creating indexed get/set methods on your bean:

+
+
+
+

In your JSP pages, you access individual entries in a list-backed property by using a different special notation: listname[index]. The braces in the bean property name indicate that the bean property named listname is indexed (probably backed by a List), and that struts should look for get/set methods that take an index parameter in order to find the correct sub-property value.