Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date and Dollar amounts in Form Beans

 
Kiran Kumar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic