The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

entfred (3) [Avatar] Offline
Section 7.4.3 explains validating input. What about validating numeric input that is
stored as a BigDecimal?

For example:

@Column(name = "COST_DOLLARS", precision = 11, nullable = false)
private BigDecimal costDollars;

How would you validate this in Spring? Since data binding happens before validation,
if the user enters "A" instead of 100.00 in the costDollars field on a jsp form, how
do you validate costDollars? Does @Valid and JSR-303 work for numeric data? Or does it just work for character data? I would like to avoid storing costDollars in a character variable and then having to convert it to a numeric variable. I was finding that JSR-303 works fine for character validation but seems to not work for variables, such as costDollars.

Thanks for any advice on this.