aspose file tools*
The moose likes Struts and the fly likes Date and Dollar amounts in Form Beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Date and Dollar amounts in Form Beans" Watch "Date and Dollar amounts in Form Beans" New topic
Author

Date and Dollar amounts in Form Beans

Kiran Kumar
Ranch Hand

Joined: Jan 06, 2003
Posts: 91
Hello,

I saw that <bean:write> has a "format" attribute for formatting dates and dollar values. But I didn't see similar thing for <html:text>. If my bean has a property called "amount" of type BigDecimal, and I want to display that as a <html:text> for the user to modify the value, How can I format it?

Also, if the user leaves the <html:text> field for BigDecimal as blank, I get an exception. So, is the solution to this is to make all formbean properties to be "String" type?


Thanks,
Kiran


------------<br />SCJP
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Yes, chaging your ActionForm property to type String is recommended. Convert the BigDecimal to a String when populating your form bean. When the user submits the form, you would then apply validation logic to the property to test whether it will convert to the desired numeric type and scope. Once it has passed validation, you can then convert it back to BigDecimal for use in your model classes.


Merrill
Consultant, Sima Solutions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Date and Dollar amounts in Form Beans