Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes Valid Property Types in DynaActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Valid Property Types in DynaActionForm " Watch "Valid Property Types in DynaActionForm " New topic
Author

Valid Property Types in DynaActionForm

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
The following is part of the store front sample appli from Oreilly's Programming struts 2nd edition:

<form-beans>
<form-bean name="loginForm" type="com.oreilly.struts.storefront.security.LoginForm"/>
<form-bean
name="itemDetailForm"
dynamic="true"
type="org.apache.struts.action.DynaActionForm">
<form-property name="view" type="com.oreilly.struts.storefront.catalog.view.ItemDetailView"/>
</form-bean>
...
</form-beans>

The problem is the view property of the DynaActionForm is Object type. Is it a valid type? I checked struts online documentation which lists a couple of valid types but it does not include java.lang.Object!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In a DynaActionForm, as with any ActionForm, properties can be Strings, Booleans, or an object whose properties are strings or booleans. Other types such as Integer and Date will work if all you're doing is outputting them, but if they're being used on input controls, you can run into problems with validation.


Merrill
Consultant, Sima Solutions
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
This is a bit confusing. Because in Struts offical site's documentation:
struts.apache.org on DynaActionForm

It says:

The types supported by DynaActionForm include:

java.lang.BigDecimal
java.lang.BigInteger
boolean and java.lang.Boolean
byte and java.lang.Byte
char and java.lang.Character
java.lang.Class
double and java.lang.Double
float and java.lang.Float
int and java.lang.Integer
long and java.lang.Long
short and java.lang.Short
java.lang.String
java.sql.Date
java.sql.Time
java.sql.Timestamp
You may also specify Arrays of these types (e.g. String[]). You may also specify a concrete implementation of the Map Interface, such as java.util.HashMap, or a List implementation, such as java.util.ArrayList.

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

Joined: Jan 28, 2004
Posts: 569
I mean the list doesnt include java.lang.Object. I suppose that is a list of ALL supported types - those not listed are NOT supported.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The mechanism behind the DynaActionForm is just a java.util.Map, so really, you can store any object type you wish in a property. I'm not sure why they even make a list of officially supported objects.

It's quite often convenient to nest other objects in your form bean, and use the properties of those objects to display data.

Read the following from the official struts website, and I think you'll understand better why it's OK to put user defined objects in a form.

http://struts.apache.org/faqs/indexedprops.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Valid Property Types in DynaActionForm