Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XWorkBasicConverter to trim spaces for numeric fields?

 
Xolani Nkosi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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?
 
Richard Golebiowski
Ranch Hand
Posts: 213
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic