-->
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.  [ 4 posts ] 
Author Message
 Post subject: Validating optional fields
PostPosted: Thu Dec 30, 2010 10:47 am 
Newbie

Joined: Sun Feb 14, 2010 10:13 am
Posts: 17
hi

suppose i have a group of 3 fields, tel1 tel2 tel3, and i want to validate that at least one of them is @NotEmpty, but not necessarily all of them.
is there a way for me to do it without writing my own custom validation annotation?

thanks.


Top
 Profile  
 
 Post subject: Re: Validating optional fields
PostPosted: Thu Dec 30, 2010 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Not without only using Bean Validation specific constraints. However, Hibernate Validator contains a @ScriptAssert annotation with which you can achieve what you want.


Top
 Profile  
 
 Post subject: Re: Validating optional fields
PostPosted: Thu Dec 30, 2010 12:30 pm 
Newbie

Joined: Sun Feb 14, 2010 10:13 am
Posts: 17
thanks, i understand that this is a rather new annotation from Hibernate Validator 4.1.0, i will look into it.


Top
 Profile  
 
 Post subject: Re: Validating optional fields
PostPosted: Thu Dec 30, 2010 12:33 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Right. It was introduced into 4.1.x. It requires the availability of a scripting engine, but with Java 6 a Javascript engine is included.
If you don't want to use @ScriptAssert you would have to write a custom class level constraint.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.