*
The moose likes EJB and other Java EE Technologies and the fly likes Can JSR 303, be used to achieve complex validations involving multiple objects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Can JSR 303, be used to achieve complex validations involving multiple objects?" Watch "Can JSR 303, be used to achieve complex validations involving multiple objects?" New topic
Author

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

Jeevan Sunkersett
Ranch Hand

Joined: Jul 03, 2007
Posts: 77
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

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can JSR 303, be used to achieve complex validations involving multiple objects?
 
Similar Threads
how to make bean object in servlets to get values in jsp
Good books or tutorial site for JDO
Customising generated JAXB Classes with custom annotations
Advanced Inheritance.
can i assign an error message for validation annotation from a .properties file