17 Mai 2010

Missing Feature in Bean Validation

After using Bean Validation for some month I had a problem that I couldn't solve.

It's not possible to add "dynamic" parameters to the validation message. For example if you want to pass the id of your entity that fails and want to use that id in your custom MessageInterpolator.

We solved this be adding the parameters at the end of the message separated by #. So we could extract them in our MessageInterpolator and exchange {0}...{n} to the parameters passed.

But in my opinion this is an evil hack!
My suggestion is to change the type of the message in the method interpolate of the MessagInterpolator to something like ValidationMessage that could have a collection of object as parameters.

I will post this as a feature request to the JSR 303 expert group.

Kommentare:

Charpentier Damien hat gesagt…

Hi, do you know if they acknowledged this issue? Thanks !

Simon Martinelli hat gesagt…

I don't know. They are working on Bean Validation 1.1. Have a look at the spec.