I know I can do this and it seems that struts can convert input parameter (String) into BigDecimal automatically. Furthermore, I can also use BigDecimal type in DynaActionForm and the similar conversion is done automatically.
But, the problem is if I input some non-numeric value in the text box which is incompatible with BigDecimal's constructor, struts throws an exception in the browser! Is there any way to catch the exception? Or, is it a good design to use BigDecimal at all?
Afterall DynaActionForm does support it and a bunch of other non-String type, so I guess there is some good reasons behind this. But, If it is a good design, there would be another problem. How can the ActionForm store the invalid input value (some non numeric character) in BigDecimal and redisplay it in the response?
posted 11 years ago
I find it easier to use String properties only in the ActionForms and convert back and forth to numbers in my Action classes if I need to, it makes things easier in the jsp. I think the struts tags will try to convert anything to a String anyway but if you do it yourself you can guarantee it will be done and can handle removing any excess decimal places you don't want and such