husted 2002/10/11 15:00:23
Modified:doc/userGuide index.xml building_controller.xml
Log:
New 1.1 sections contributed by Donald Ball.
Revision ChangesPath
1.17 +1 -0 jakarta-struts/doc/userGuide/index.xml
Index: index.xml
===
RCS file: /home/cvs/jakarta-struts/doc/userGuide/index.xml,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- index.xml 10 Oct 2002 03:42:44 - 1.16
+++ index.xml 11 Oct 2002 22:00:23 - 1.17
@@ -26,6 +26,7 @@
authorRobert Leland/author
authorStanley Santiago/author
authorWong Kok Kai/author
+authorDonald Ball/author
authorDan Walker/author
authorEddie Bush/author
authorYann Cebron /author
1.30 +88 -5 jakarta-struts/doc/userGuide/building_controller.xml
Index: building_controller.xml
===
RCS file: /home/cvs/jakarta-struts/doc/userGuide/building_controller.xml,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- building_controller.xml 11 Oct 2002 21:48:15 - 1.29
+++ building_controller.xml 11 Oct 2002 22:00:23 - 1.30
@@ -7,6 +7,7 @@
authorTed Husted/author
authorMartin Cooper/author
authorEd Burns/author
+authorDonald Ball/author
authorEddie Bush/author
authorYann Cebron /author
authorDavid Graham/author
@@ -93,12 +94,94 @@
/section
section name=4.2.1 DynaActionForm Classes href=dyna_action_form_classes
- p[:TODO:]/p
- /section
- section name=4.2.2 Map-backed ActionForms href=map_action_form_classes
- p[:TODO:]/p
- /section
+ pMaintaining 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./p
+ pFor example, add the following to struts-config.xml for a UserForm bean
that stores a user's given and family names:/p
+pre
+![CDATA[
+form-bean name=UserForm type=org.apache.struts.action.DynaActionForm
+ form-property name=givenName type=java.lang.String initial=John/
+ form-property name=familyName type=java.lang.String initial=Smith/
+/form-bean
+]]
+/pre
+ pThe list of types supported by DynaActionForm beans includes:/p
+ ul
+lijava.lang.BigDecimal/li
+lijava.lang.BigInteger/li
+liboolean and java.lang.Boolean/li
+libyte and java.lang.Byte/li
+lichar and java.lang.Character/li
+lijava.lang.Class/li
+lidouble and java.lang.Double/li
+lifloat and java.lang.Float/li
+liint and java.lang.Integer/li
+lilong and java.lang.Long/li
+lishort and java.lang.Short/li
+lijava.lang.String/li
+lijava.sql.Date/li
+lijava.sql.Time/li
+lijava.sql.Timestamp/li
+ /ul
+ pIf you do not supply an initial attribute, numbers will be initialized to
0 and objects to null./p
+ /section
+
+section name=4.2.2 Map-backed ActionForms href=map_action_form_classes
+ pThe 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./p
+ pStruts 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:/p
+pre
+![CDATA[
+public FooForm extends ActionForm {
+
+private final Map values = new HashMap();
+
+public void setValue(String key, Object value) {
+values.put(key, value);
+}
+
+public Object getValue(String key) {
+return values.get(key);
+}
+
+}
+]]
+/pre
+ pIn its corresponding JSP page, you can access objects stored in the values
map using a special notation: imapname(keyname)/i. The parentheses in the bean
property name indicate that the bean property named imapname/i 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 ikeyname/i value from the parentheses when it calls the get/set
methods./p
+ pHere is a