Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

5.2. Setting DynaActionForm Initial Values

Problem

You need to initialize the properties in a dynamic action form declared in the struts-config.xml file.

Solution

Specify an initial value for a property of a DynaActionForm using the initial attribute of the form-property element.

<form-bean name="MyForm" type="org.apache.struts.action.DynaActionForm">
  <form-property name="firstName" type="java.lang.String"
              initial="George"/>
  <form-property name="lastName" type="java.lang.String"
              initial="Burdell"/>
  <form-property name="javaCoder" type="java.lang.Boolean"
              initial="true"/>
  <form-property name="friend" type="java.lang.String[]"
                 size="3" 
              initial="Larry,Moe,Curly"/>
</form-bean>

Discussion

DynaActionForms simplify your life as a Struts developer. There is no Java code to write, and when requirements change and you must add fields to a form, you need only change some XML and the Actions that use the form. When working with these forms, a common question that comes up is how to populate the form with initial values. The Solution shows how this can be done using the initial attribute of the form-property element. This attribute specifies a default value for a property. The property is set to this value when the form is created or when the initialize( ) method is called on the form. The time of creation depends on the scope of the form. If the scope is "request," a new form is created for each new request that uses the form. For session scope, the form is created when it can't be found in the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page