• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can JSR 303, be used to achieve complex validations involving multiple objects?

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am fairly new to JSR 303, Bean validation.
I wish to know how I can use it for validating certain complex conditions, for instance

I have a object:

1. Person (name, age)
2. Account (type, minimumBalance, dailyWithdrawalLimit)


I think we can use JSR 303, to validate Person or Account alone, say
a. person.age must be more than 5.
b. person.name cannot be blank
c. account.type can have only 2 values - 'Savings' or 'Checking'


Is it possible to use JSR 303, for something more complex;
eg.


a. If account.type = 'Savings' then
account.minimumBalance IS $1000/-
account.dailyWithdrawalLimit IS $ 5000/-

but If account.type = 'Current' then
account.minimumBalance IS $ 1.0/-



Is it possible to use JSR 303, alone (nothing else) to validate across objects?

eg. If person.age < 17, then account.type CAN-Only-be 'Savings'



If it is not possible, to use JSR 303 alone, what will I have to use in addition to JSR 303?

Would appreciate if can point me to links/ blogs/ articles, which show case, how such validations are achieved.

thank you
Jeevan
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create an annotation and apply it to the entire bean class (Account). With that you can perform any validation on any combination of fields.
 
crispy bacon. crispy tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic