• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XWorkBasicConverter to trim spaces for numeric fields?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using an s:textfield to populate a field on an action when the user submits a form. Currently, the user typing a number followed by a space into a field backed by a numeric object produces a conversion error. It'd be nice if for numeric fields, the attempt would be made with the trimmed input, so '51 ' is converted to 51 and not rejected.

Looks like the magic for converting user input to the standard java types is going on in XWorkBasicConverter. So has anyone attempted a patch to the XWorkBasicConverter class to trim strings when attempting to convert the user input for numeric fields? Or do I need to grab the source and give it a stab?
 
Ranch Hand
Posts: 213
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While you could modify the converter or implement your own converter to deal with this, a better solution would be to filter the input client side so that only numbers could be input. My personal favorite is a script library called fiterinput.js that you can download off the web.
 
Xolani Nkosi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Golebiowski wrote:While you could modify the converter or implement your own converter to deal with this, a better solution would be to filter the input client side so that only numbers could be input. My personal favorite is a script library called fiterinput.js that you can download off the web.


Mm, but I can't rely on the browser having javascript enabled. And the most frequent place spaces arise is when copy/pasting a value - that loves to tack an extra space on the end fnar. So making the converter robust enough to try a trim before rejecting input as not a number would be ideal. If I'm on the right track with modifying that class, I'll give that go.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic