File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Date and Dollar amounts in Form Beans" Watch "Date and Dollar amounts in Form Beans" New topic

Date and Dollar amounts in Form Beans

Kiran Kumar
Ranch Hand

Joined: Jan 06, 2003
Posts: 91

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?


------------<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.

Consultant, Sima Solutions
I agree. Here's the link:
subject: Date and Dollar amounts in Form Beans
It's not a secret anymore!