1 posts in topic
Flat View  Flat View

Posted By:   laeticia_corlean
Posted On:   Tuesday, October 15, 2002 01:25 AM

Could anyone point me to a doc (or any whitepaper) explaning the concept of these tags - I have a vague idea of what the do, but it is not clear.


Re: <form-beans><form-bean><form-property>

Posted By:   Ziad_Mannan  
Posted On:   Tuesday, October 15, 2002 04:49 PM

There is a book to be released v.soon (i think end of Oct 2002 or Nov 2002) by Chuck Cavaness, published by O'Rielly which had quite a few chapters for download on theserverside.com for review. But it is not there any more, this was the best resource I found while trying to learn struts. Here is a section about the configuration from the book. I hope this helps.


p.s. some of the formatting is bad because the data was in tables!


As you learned from Chapter 3, a form bean is a JavaBean class that extends the org.apache.struts.action.ActionForm class. Example 4-6 shows how the form-beans element can be configured in the configuration file.
Example 4-6. A partial struts-config.xml file showing the form-beans section



One of the elements in Example 4-6 uses a new feature to Struts 1.1 called dynamic action forms. The purpose of dynamic action forms was discussed in Chapter 3.
You can pass one or more dynamic properties to an instance of the org.apache.struts.action.DynaActionForm class using the element. It’s only supported when the type attribute of the surrounding element is “org.apache.struts.action.DynaActionForm”, or descendant.
Each form-bean element also has five attributes that you can specify. Two of the attributes are required and the rest are optional. Table 4-4 lists the attributes.
Table 4-4. The attributes of the form-bean element
Name Description
className If you don’t want to use the standard configuration bean org.apache.struts.config.FormPropertyConfig, you can specify your own class here. This attribute is not required.
initial A string representation of the initial value for this property. If not specified, primitives will be initialized to zero and objects to null. This attribute is not required.
name The JavaBeans property name of the property being described by this element. This attribute is required.
type The fully qualified Java class name of the implementation class of this bean property, optionally followed by "[ ]" to indicate that this property is indexed. This attribute is required.
This is a very nice feature in 1.1 because it saves you development time from having to create a bunch of ActionForm classes that just pass data from the HTML pages to the backend. The DynaActionForm extends the ActionForm class so you will need to perform an explicit cast on the ActionForm object within the execute method of your Action class to retrieve the properties.
Since the DynaActionForm instance is created dynamically, the validate() method doesn’t provide any default validation behavior, so you may have to perform the validation in your Action class. The reset() method will still be called and the values will be reset back to the default state. Action forms will be discussed further in Chapter 7.
About | Sitemap | Contact