• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Valid Property Types in DynaActionForm

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic