This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Valid Property Types in DynaActionForm " Watch "Valid Property Types in DynaActionForm " New topic

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-bean name="loginForm" type=""/>
<form-property name="view" type="com.oreilly.struts.storefront.catalog.view.ItemDetailView"/>

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.

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: on DynaActionForm

It says:

The types supported by DynaActionForm include:

boolean and java.lang.Boolean
byte and java.lang.Byte
char and java.lang.Character
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
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.
I agree. Here's the link:
subject: Valid Property Types in DynaActionForm
It's not a secret anymore!