This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question about the ActionForm 's property type

 
gao zhixin
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ActionForm's property can be which type? The struts documentation doesn't mention, please tell me!
 
Ravi Seshu
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int Integer, float Float,Doublt double,boolean Boolean, BigInteger,java.util.list
 
Ravi Seshu
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
short Short,date Date,Timestamp,BigDecimal, short Short,Class,String,byte Byte
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic