aspose file tools*
The moose likes Struts and the fly likes a question about the ActionForm 's property type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "a question about the ActionForm Watch "a question about the ActionForm New topic
Author

a question about the ActionForm 's property type

gao zhixin
Ranch Hand

Joined: Jan 18, 2006
Posts: 42
The ActionForm's property can be which type? The struts documentation doesn't mention, please tell me!
Ravi Seshu
Ranch Hand

Joined: Mar 19, 2005
Posts: 38
int Integer, float Float,Doublt double,boolean Boolean, BigInteger,java.util.list
Ravi Seshu
Ranch Hand

Joined: Mar 19, 2005
Posts: 38
short Short,date Date,Timestamp,BigDecimal, short Short,Class,String,byte Byte
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You can define a property of any type in an ActionForm.

-- BUT --

If you're using a property in an <html:xxxx> tag, Struts will call the setter for the property when it populates the ActionForm. In this case, it is recommended that the property be either a String or a boolean. If you have a setter that accepts an object other than String such as java.util.Date, java.lang.Integer, etc. Struts will throw an exception when it tries to populate the ActionForm.

For primitives such as int, Struts will call the setter OK, but if the value entered cannot be translated to an int, Struts will throw a NumberFormatException. Even if you use validation on the field, it's still better to define it as String and convert it to an int later if necessary. If the property is read-only, however, I don't see any problems with using a primitive.

It's OK to have nested objects. For example, you could have a property of type Customer, and in your ActionForm, and in your JSP have <html:text property="customer.name" /> However, the name property of the Customer object should conform to the above restrictions.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a question about the ActionForm 's property type