aspose file tools*
The moose likes Struts and the fly likes XWorkBasicConverter to trim spaces for numeric fields? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "XWorkBasicConverter to trim spaces for numeric fields?" Watch "XWorkBasicConverter to trim spaces for numeric fields?" New topic
Author

XWorkBasicConverter to trim spaces for numeric fields?

Xolani Nkosi
Ranch Hand

Joined: Apr 29, 2009
Posts: 32
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

Joined: May 05, 2010
Posts: 213

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

Joined: Apr 29, 2009
Posts: 32
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XWorkBasicConverter to trim spaces for numeric fields?
 
Similar Threads
Validator Framework and Javascript
B&S: Customer ID Number
Converting a date to numeric
Custom UIComponent?
Spring Webflow: Type Mismatch error is thrown even after setting Validation to false