-->
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.  [ 2 posts ] 
Author Message
 Post subject: Different Hibernate validation annotations on same property
PostPosted: Thu Oct 21, 2010 4:48 am 
Newbie

Joined: Thu Oct 21, 2010 4:43 am
Posts: 1
Greetings all i am using two validation annotations on a property in the java bean

@NotEmpty(message = "{name.required}")
@Pattern(regex = "^([A-Za-z0-9]{2,}(\\-[a-zA-Z0-9])?)$", message = "{invalid.name}")
private String name;

if i left the name empty i got the two errors and i want only the first error message (if the first condition occurs show its error message then skip the second condition).


Top
 Profile  
 
 Post subject: Re: Different Hibernate validation annotations on same property
PostPosted: Fri Oct 22, 2010 10:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

that seems to be a case for @GroupSequence. Check the documentation for group sequences.
An alternative in your case would be to let the pattern also match the empty string. Something like this: "|^([A-Za-z0-9]{2,}(\\-[a-zA-Z0-9])?)$"

--Hardy


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