• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

spring mvc convert from string to currency

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic