lundi 2 mars 2015

Custom message for overflowed number during binding in Spring

I have a web application wrote in Spring. There is a HTML form with one Integer field. I added a custom message for typeMismatch.java.lang.Integer and it is correctly handled but there is one issue. Spring does not distinguish between a string value and "overflowed" integer. In other words - there is no difference whether user enter this is a string or 1000000000000000000000000000. Both are handled by Spring as typeMismatch. I would like to have two separate messages for both cases.


I thought about two solutions:



  1. replace the java.lang.Integer by java.math.BigInteger in the form object - then the typeMismatch error will apply only to this is a string and I will handle 1000000000000000000000000000 in a validator

  2. register my own property editor for Integer, but I'm not sure if I could handle two different errors with one property editor


Do you have any better concepts for this issue?


Aucun commentaire:

Enregistrer un commentaire