I want to apply certain @NotBlank annotations only if another field is false. On my current project we have to use hibernate validator, so no commons validation + valang available to solve this.
Since I'm not too fond of creating multiple custom annotations just to solve what should be an easy thing (bit bummed that this isn't part of the JSR-303 spec) I was wondering if anyone knew an acceptable way to accomplish this. I found a jar which accomplished that, but that was for hibernate 3. And due to the changes...
For this case, the suggested approach is to use class-level constraints instead Field or Property Level.
Please refer Hibernate Validator Docs
I now it is annoying. I had a scenario like this and tried something like @NotEmpty(depends="anotherField") and it was a totally failure.
Maybe some other members know another way to do this, but for now, I'm doing what Hibernate Validator says to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With