I have a form (Spring 3 MVC project) and I use DTO (data transfer object) to validate the data. Data is sent to the controller, and I verify its validity using the BindingResult.hasErrors() method and corresponding annotations. I'm going to simplify here, as I have a problem with numeric fields.
DTO:
public class Item { private String discount; @Digits(integer = 15, fraction = 2) public String getDiscount() { return discount; } }
If I submit the form without anything written in the discount field, BindingResult.hasErrors() will return true with a message
numeric value out of bounds (<15 digits>.<2 digits> expected) .
What I want to do is that the discount field may be empty, but if something is written in it, it should be in the number format provided by the @Digits annotation. How can i do this?
source share