-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Validation with a condition of another attribute
PostPosted: Tue Jan 12, 2010 4:44 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 3:36 pm
Posts: 78
In a domain class, a pair of fields as

Code:
...
       private String saleTaxName;

       private BigDecimal saleTax;



The validation logic shall be a non-zero value in saleTax when saleTaxName is not blank and the saleTaxName field isn't blank when the saleTax is bigger than zero. Otherwise, saleTaxName is blank and saleTax is zero. How to express this validation logic with the Hibernate validator?


Top
 Profile  
 
 Post subject: Re: Validation with a condition of another attribute
PostPosted: Tue Jan 12, 2010 4:55 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
A custom class level constraint would be your best bet. In this case you get the whole domain object passed into the validation method and you can do any cross checks you like. Check the online docs for that - http://docs.jboss.org/hibernate/stable/ ... ml_single/

--Hardy


Top
 Profile  
 
 Post subject: Re: Validation with a condition of another attribute
PostPosted: Fri Jan 15, 2010 8:12 am 
Newbie

Joined: Fri Jan 15, 2010 5:38 am
Posts: 2
I have a simmilar problem. The validation depends on an additional parameter or field.
We have different Customers they can be generated dynamically together with an profile (this is stored in the DB). depending on this value the Validation is different.
Validations on the hole Object is a very bad Option. Can we do validations with a given Parameter?


Top
 Profile  
 
 Post subject: Re: Validation with a condition of another attribute
PostPosted: Fri Jan 15, 2010 9:28 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
What do you mean with "validation with a given parameter". How would this look like in your opinion?

--Hardy


Top
 Profile  
 
 Post subject: Re: Validation with a condition of another attribute
PostPosted: Fri Jan 15, 2010 11:17 am 
Newbie

Joined: Fri Jan 15, 2010 5:38 am
Posts: 2
if you call the validation method you might pass over an additional parameter like this:

validator.validate (objectToFactor, parameter);

this parameter might be the customer in our case. But this is just a suggestion.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.