-->
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: [Solved] Password confirmation validation - annotated
PostPosted: Fri Nov 27, 2009 3:01 pm 
Newbie

Joined: Fri Nov 27, 2009 2:57 pm
Posts: 3
Hello
Is there any possibility to confirm that two fields have the same value ?


I need to make "create account" form with "password" and "confirm password".
I must use annotations, but I didn't find any appropriate.

Please tell me if there is any annotation which can do this or maybe how to make custom annotation which will do this.

Please remember that i'm begginer.

Thanks in advance!


Last edited by michalborek on Wed Dec 02, 2009 3:42 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Password confirmation validation - annotated
PostPosted: Mon Nov 30, 2009 7:27 pm 
Hibernate Team
Hibernate Team

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

i guess your best bet would be a custom class level constraint. Check the online documentation to see how to implement such a constraints - http://docs.jboss.org/hibernate/stable/ ... le/#d0e328

Using a class level constraint you will get passed the whole entity you are currently validating. If this entity constains a password and confirm password field you can just compare these two values.

--Hardy


Top
 Profile  
 
 Post subject: Re: Password confirmation validation - annotated
PostPosted: Mon Nov 30, 2009 7:57 pm 
Newbie

Joined: Fri Nov 27, 2009 2:57 pm
Posts: 3
hardy.ferentschik wrote:
Hi,

i guess your best bet would be a custom class level constraint. Check the online documentation to see how to implement such a constraints - http://docs.jboss.org/hibernate/stable/ ... le/#d0e328

Using a class level constraint you will get passed the whole entity you are currently validating. If this entity constains a password and confirm password field you can just compare these two values.

--Hardy


Thanks for your answer!

Yes I made such solution, but unfortunately I don't know how to assign error to field, not to class. It's important because I use Annotated validator in Spring and errors are automatically assigned to html form fields.


Top
 Profile  
 
 Post subject: Re: Password confirmation validation - annotated
PostPosted: Mon Nov 30, 2009 10:23 pm 
Hibernate Team
Hibernate Team

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

try using the ConstraintValidatorContext.
Something like this:
Code:
constraintValidatorContext.disableDefaultConstraintViolation();
constraintValidatorContext.buildConstraintViolationWithTemplate( "foo" )
           .addNode( "password" )
           .addConstraintViolation();


--Hardy


Top
 Profile  
 
 Post subject: Re: Password confirmation validation - annotated
PostPosted: Wed Dec 02, 2009 3:41 pm 
Newbie

Joined: Fri Nov 27, 2009 2:57 pm
Posts: 3
I works! Thanks a lot.

Btw. It didn't work in Spring 3.0.0RC1 (if someone would have problems with that), but it works in RC3


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.