Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Validator for Java Beans

 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jai .. in-fact i was'nt clear either.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic