-->
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: Short circuiting constraints on a field (Bean validation)
PostPosted: Fri Oct 11, 2013 6:14 am 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
Hi All,

I am wondering about way to enable short circuiting on constraint defined on field levels.Say i have a field

Code:
private Integer phoneNumber;
and i have following validations on phoneNumber
Code:
        @Digits(message="not.number")
   @SecondValidation(value=10,message="my message")
        private Integer phoneNumber;


In case i added alphanumeric value less than, i am getting both errors

1. Field should be number.
2. Second Message will also be displayed

Is there any way to tell BV API to not go for other validation if first one failed (Short circuiting). In short i want to display only first error if it failed and ignoring any other validation defined on that field / property

Is this feasible?

Thanks
Umesh


Top
 Profile  
 
 Post subject: Re: Short circuiting constraints on a field (Bean validation)
PostPosted: Fri Oct 11, 2013 7:59 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Group sequences (http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-defining-group-sequences) may be helpful for you.

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Short circuiting constraints on a field (Bean validation)
PostPosted: Fri Oct 11, 2013 8:24 am 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
Thanks for your inputs, let me to provide more details, i am working on a plugin which will work as a bridge between Bean Validator and underlying framework.

Though Group sequence seems to do work , but in my case it will not work as i do not want to restrict anything, i was exploring a possible way where user can define his preference if they want short circuit evaluation or not and based on there preferences plugin should handle this.

I was thinking may be there might be some kind of flag which can be passed to Bean validation API to indicate that we want to have short circuit validation and not complete one.

Thanks
Umesh


Top
 Profile  
 
 Post subject: Re: Short circuiting constraints on a field (Bean validation)
PostPosted: Mon Oct 14, 2013 3:19 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hibernate Validator does provide a so-called "fail fast" mode (http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-fail-fast) which causes validation to abort after the first violation. This might be helpful for your case (you can bootstrap different validators with different fail fast settings via the usingContext() API) but not that no order is implied in which the constraints are validated.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.