-->
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.  [ 3 posts ] 
Author Message
 Post subject: Conditional Validation
PostPosted: Mon May 30, 2011 11:55 am 
Newbie

Joined: Thu May 05, 2011 6:33 am
Posts: 16
In italy we have a code, called Codice Fiscale, which is for person and corporate.
For person can be 16 and for corporate can be 11.
I think can be useful a condition annotation like @OR(@Lenght(11),@Length(16)).

Any suggestion, for avoiding custom "validator"

_________________
Luca Preziati


Top
 Profile  
 
 Post subject: Re: Conditional Validation
PostPosted: Mon May 30, 2011 1:43 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi Luca,

there is something related in HV 4.2 (currently released as Beta version) which might help you. There you can create composed constraints which's base constraints are joined by a logical OR:

Code:
@ConstraintComposition(OR)
@Size(min = 11, max = 11)
@Size(min = 16, max = 16)
@ReportAsSingleViolation
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
@Constraint(validatedBy = { })
public @interface CodiceFiscale {
   String message() default "codicefiscale.errorkey";
   Class<?>[] groups() default { };
   Class<? extends Payload>[] payload() default { };
}


That said you might consider to model person and corporate with separate classes and annotate each code fiscale member with the appropriate size constraint.

Hth,

Gunnar

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


Top
 Profile  
 
 Post subject: Re: Conditional Validation
PostPosted: Thu Jun 09, 2011 10:03 am 
Newbie

Joined: Thu May 05, 2011 6:33 am
Posts: 16
Thanks!

_________________
Luca Preziati


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.