File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes spring mvc convert from string to currency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "spring mvc convert from string to currency" Watch "spring mvc convert from string to currency" New topic

spring mvc convert from string to currency

gianluca gian
Ranch Hand

Joined: Aug 14, 2009
Posts: 31
Hi, I have been looking a lot around the net, to solve my problem, but actually I feel like to be very far from solution. I have a jsp page where the user can insert a monetary value, then when the page is submitted the string should be converted in a BigDecimal value. At the beginning I had on jsp a dojo component:

and on a pojo I had just private BigDecimal currency; with set and get. I liked that situation because looked simple and I could validate currency right on client side. That solution was fine except with decimal numeric since I needed currency with comma decimal separator. So I had substituted the NumberTextBox with the following:

with this kind of dojo component I could not validate currency on client side. On server side on the pojo property I did:

This solution was fine on page submit, but then on the cancel submit of the following page to the page with currency inserted by the user, an exception was thrown TypeMismatchException. Could you please suggest me a best way to validate a currency (with decimal character and comma separator) user text field and to convert it in a BigDecimal variable? Thank you
gianluca gian
Ranch Hand

Joined: Aug 14, 2009
Posts: 31
Right now I'm trying, on the client side:

and on the server side I have on my pojo:

but if I insert from client side the number: 10,44 with comma separator I got the exception typeMismatch!

gianluca gian
Ranch Hand

Joined: Aug 14, 2009
Posts: 31
another solution that I have been trying is with converter. I defined a converter like this:

where FormatUtility.convertStringToBigDecimal is an utility method that converts numeric strings like 23232,98 to BigDecimal. On spring configuration file I wrote:

but when I submit the form the converter is not called. I thought that the above configuration would be enough to trigger the convert automatically. Thanks, bye
I agree. Here's the link:
subject: spring mvc convert from string to currency
Similar Threads
Spring Web Flow 2 Web Development [Book]
any docs for spring javascript?
Any docs for spring javascript?
Populate MultiSelect Dojo box onLoad from XML data file
Spring Dojo support:customizing dojo widgets