Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Struts - Validation

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to use some of the validations that the validator framework comes with, but all of my values have commas in them. How would I strip out the comma values and then use a validation such as floatRange. Ideally I would like to be able to validate all cash quantities. 10,000 as well as 10.58 as valid.

Your help is appreciated, thanks,
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just dealt with something like that this morning actually.

Unfortunetly I don't think you can use the in-built validation on a numeric field with commas in it, as it will always seems unacceptable.

I ended up having to do build a small method to strip out all extra characters (leaving only numbers and the decimal point) and doing manual validation against that value.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could probably use the mask built-in validation.
Another option I can think of is to create your own validation and register it with validation.xml, but unfortunately the Struts Validator guide doesn't seem to say much about how to do that.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're pretty much going to having to write your own validation.

It's not that hard. Just create a new class/method that you point to with the validator-rules.xml. If you have problems with it or face a lack direction just post concerns.

If you wish to reuse some of the framework's functionality, you can use the GenericValidator from your customized method to handle range and float validation.
 
Nick Delauney
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

I have decided to format the string using onblur event with javascript on the front end. However with the javascript function my value will still have commas in it. Is it possible for a function to strip out the commas and hand over the value to the rest of the validations.

I'm thinking I have to create my own validation method that really doesnt validate but formats the value, and then follow it up with dependant validations.

i.e
<form-validation>
<formset>
<form name="someFormWithMoneyFields">
<field property="cashAmount" depends="formatMoney, floatRange, required"/>
</form>
</formset>
</form-validation>

where "formatMoney" would really be my format method?

Would this work? is it good practice?

-Thanks for any help
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic