• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jeevan Sunkersett
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic