Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validator for Java Beans

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
I have got multiple properties in Java Bean objects , which i would like to validate via configurable item (XML , property file). Any recommendations for this? Thanks.

P:S Hope i m back to JR.

 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the implementations of JSR-303, Bean validation. For example, the Hibernate validator or even the agimatec-validation
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks Jai , yep i know about Hibernate validator. And since my application is standalone and the validation also occurs in different layer , need to check on this.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I seriously doubt the use of annotation as configurable parameter. I couldn't believe how Hibernate validator ( which boasts of having bean validation with annotations) would really help.

Say i have got to validate a field with minimum and maximum characters it could take , i can hibernate built-in annotation like this



But what if my requirement changes as min as 5 , and again as max as 20 ? , does that mean i need to recompile my beans and put them back again. On the other hand , xml works way better to externalize these dependencies. Your thoughts please ?


P:S , since the thread discussion moved more on to Hibernate validator, please feel free to move it to appropriate forum.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use xml if you want to. Annotations, isn't mandatory. See chapter-7 of the Bean Validation spec.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

its seems only Hibernate Validator 4.x is fully compliant with JSR 303: Bean Validation and previous releases were not.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's correct, as per that wiki link:
As of version 4.x Hibernate Validator is based on a new code base which is the reference implementation for JSR 303: Bean Validation.


Sorry i did not know you were looking at an earlier release.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jai .. in-fact i was'nt clear either.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic